Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
luhluh-17 committed Jun 6, 2020
1 parent a2096a4 commit ed9d2bc
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 102 deletions.
42 changes: 36 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:neucalcu/models/record.dart';
import 'package:neucalcu/pages/calculator_page.dart';
import 'package:neucalcu/pages/records_page.dart';
import 'package:neucalcu/providers/calculate.dart';
import 'package:neucalcu/themes/colors.dart';
import 'package:neucalcu/themes/dimensions.dart';
import 'package:path_provider/path_provider.dart' as path;
import 'package:provider/provider.dart';

Expand All @@ -30,15 +32,43 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Calculator',
debugShowCheckedModeBanner: false,
theme: ThemeData(
textTheme: GoogleFonts.montserratTextTheme(Theme.of(context).textTheme),
visualDensity: VisualDensity.adaptivePlatformDensity,
),
theme: _buildAppTheme(context),
initialRoute: CalculatorPage.id,
routes: {
CalculatorPage.id : (context) => CalculatorPage(),
RecordsPage.id : (context) => RecordsPage(),
CalculatorPage.id: (context) => CalculatorPage(),
RecordsPage.id: (context) => RecordsPage(),
},
);
}

ThemeData _buildAppTheme(BuildContext context) {
final ThemeData base = ThemeData.light();

return base.copyWith(
textTheme: _appTextTheme(
GoogleFonts.montserratTextTheme(base.textTheme),
),
visualDensity: VisualDensity.adaptivePlatformDensity);
}

TextTheme _appTextTheme(TextTheme base) {
return base
.copyWith(
headline1: base.headline1.copyWith(fontSize: sizeHeadline1),
headline2: base.headline2.copyWith(fontSize: sizeHeadline2),
headline3: base.headline3.copyWith(fontSize: sizeHeadline3),
headline4: base.headline4.copyWith(fontSize: sizeHeadline4),
headline5: base.headline5.copyWith(fontSize: sizeHeadline5),
headline6: base.headline6.copyWith(fontSize: sizeHeadline6),
subtitle1: base.subtitle1.copyWith(fontSize: sizeSubtitle1),
subtitle2: base.subtitle2.copyWith(fontSize: sizeSubtitle2),
bodyText1: base.bodyText1.copyWith(fontSize: sizeBody1),
bodyText2: base.bodyText2.copyWith(fontSize: sizeBody2),
caption: base.caption.copyWith(fontSize: sizeCaption),
)
.apply(
bodyColor: AppColors.primaryText,
displayColor: AppColors.secondaryText,
);
}
}
8 changes: 4 additions & 4 deletions lib/pages/calculator_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class _CalculatorPageState extends State<CalculatorPage> {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light.copyWith(
statusBarColor: Colors.transparent,
systemNavigationBarColor: AppColors.darkShadow),
systemNavigationBarColor: AppColors.primaryDark),
child: Scaffold(
backgroundColor: AppColors.baseColor,
backgroundColor: AppColors.primary,
body: Padding(
padding: EdgeInsets.all(16.0),
padding: EdgeInsets.all(sizeBody1),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Expand All @@ -41,7 +41,7 @@ class _CalculatorPageState extends State<CalculatorPage> {
'NeuCalcu',
style: TextStyle(
color: Colors.white54,
fontSize: sizeSubHead2,
fontSize: sizeSubtitle1,
),
),
CustomIconButton(
Expand Down
35 changes: 21 additions & 14 deletions lib/pages/records_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import 'package:neucalcu/models/record.dart';
import 'package:neucalcu/themes/colors.dart';
import 'package:neucalcu/themes/dimensions.dart';
import 'package:neucalcu/widgets/custom_icon_button.dart';
import 'package:neucalcu/widgets/empty_data.dart';
import 'package:neucalcu/widgets/record_container.dart';

const double _padding = 16.0;
const double _padding = sizeBody1;

class RecordsPage extends StatelessWidget {
static const String id = '/records';
Expand All @@ -17,7 +16,7 @@ class RecordsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.baseColor,
backgroundColor: AppColors.primary,
body: Column(
children: <Widget>[
SizedBox(height: 25.0),
Expand All @@ -40,10 +39,7 @@ class RecordsPage extends StatelessWidget {
),
Text(
'Record History',
style: TextStyle(
color: AppColors.primaryText,
fontSize: sizeSubHead2,
),
style: Theme.of(context).textTheme.subtitle2
),
Positioned(
right: 0,
Expand Down Expand Up @@ -76,19 +72,30 @@ class RecordListViewBuilder extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Expanded(
child: ListView.builder(
child: ListView.separated(
padding: EdgeInsets.all(sizeBody1),
physics: BouncingScrollPhysics(),
padding: EdgeInsets.only(
left: _padding,
right: _padding,
bottom: _padding,
),
itemCount: box.length,
itemBuilder: (context, index) {
separatorBuilder: (_, index) => SizedBox(height: 24.0),
itemBuilder: (_, index) {
final Record record = box.get(index);
return RecordContainer(record: record);
},
),
);
}
}

class EmptyData extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Expanded(
child: Center(
child: Text(
'Empty Data',
style: Theme.of(context).textTheme.headline3,
),
),
);
}
}
8 changes: 4 additions & 4 deletions lib/themes/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ class AppColors {
static const int _blue = 33;
static const int _brightness = 25;

static const Color baseColor = Color.fromRGBO(_red, _green, _blue, 1);
static const Color lightShadow = Color.fromRGBO(
static const Color primary = Color.fromRGBO(_red, _green, _blue, 1);
static const Color primaryLight = Color.fromRGBO(
(_red + _brightness), (_green + _brightness), (_blue + _brightness), 1);
static const Color darkShadow = Color.fromRGBO(
static const Color primaryDark = Color.fromRGBO(
(_red - _brightness), (_green - _brightness), (_blue - _brightness), 1);

static const Color primaryText = Colors.white;
static const Color secondaryText = Colors.white38;
static const Color accent = Colors.amberAccent;
static const Color danger = Colors.redAccent;
}
}
19 changes: 10 additions & 9 deletions lib/themes/dimensions.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const double sizeCustom1 = 76.29;
const double sizeCustom2 = 61.04;
const double sizeDisplay = 48.83;
const double sizeHeadline1 = 39.06;
const double sizeHeadline2 = 31.25;
const double sizeSubHead1 = 25.00;
const double sizeSubHead2 = 20.00;
const double sizeBody = 16.0;
const double sizeDefault = 14.0;
const double sizeHeadline1 = 76.29;
const double sizeHeadline2 = 61.04;
const double sizeHeadline3 = 48.83;
const double sizeHeadline4 = 39.06;
const double sizeHeadline5 = 31.25;
const double sizeHeadline6 = 25.0;
const double sizeSubtitle1 = 20.0;
const double sizeSubtitle2 = 16.0;
const double sizeBody1 = 16.0;
const double sizeBody2 = 14.0;
const double sizeCaption = 12.80;
10 changes: 5 additions & 5 deletions lib/themes/shadows.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:neucalcu/widgets/concave_decoration.dart';
import 'file:///C:/AppFlutter/LuhLuh/neumorphic_calculator/lib/widgets/concave_decoration.dart';

import 'colors.dart';

Expand All @@ -12,25 +12,25 @@ ConcaveDecoration getInnerShadow({double radius = _radius}) {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(radius),
),
colors: [AppColors.lightShadow, AppColors.darkShadow],
colors: [AppColors.primaryLight, AppColors.primaryDark],
depth: 6.0,
);
}

BoxDecoration getOuterShadow({double radius = _radius}) {
return BoxDecoration(
borderRadius: BorderRadius.circular(radius),
color: AppColors.baseColor,
color: AppColors.primary,
boxShadow: [
BoxShadow(
blurRadius: _blurRadius,
offset: -_offset,
color: AppColors.lightShadow,
color: AppColors.primaryLight,
),
BoxShadow(
blurRadius: _blurRadius,
offset: _offset,
color: AppColors.darkShadow,
color: AppColors.primaryDark,
),
],
);
Expand Down
9 changes: 9 additions & 0 deletions lib/utils/formats.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:intl/intl.dart';

String getFormattedDate({String date}) {
DateTime dateTime = DateTime.parse(date);
DateFormat formatter = new DateFormat('MMMM dd, yyyy K:mm a');
String formattedDate = formatter.format(dateTime);

return formattedDate;
}
18 changes: 9 additions & 9 deletions lib/widgets/button_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ class ButtonContainer extends StatelessWidget {
CalculatorButton(
text: '×',
color: AppColors.accent,
fontSize: sizeHeadline1,
fontSize: sizeHeadline4,
),
CalculatorButton(
text: '÷',
color: AppColors.accent,
fontSize: sizeHeadline1,
fontSize: sizeHeadline4,
),
],
),
Expand All @@ -48,12 +48,12 @@ class ButtonContainer extends StatelessWidget {
CalculatorButton(
text: '+',
color: AppColors.accent,
fontSize: sizeHeadline1,
fontSize: sizeHeadline4,
),
CalculatorButton(
text: '-',
color: AppColors.accent,
fontSize: sizeHeadline1,
fontSize: sizeHeadline4,
),
],
),
Expand All @@ -63,22 +63,22 @@ class ButtonContainer extends StatelessWidget {
CalculatorButton(
text: '(',
color: AppColors.accent,
fontSize: sizeSubHead1,
fontSize: sizeHeadline6,
),
CalculatorButton(
text: ')',
color: AppColors.accent,
fontSize: sizeSubHead1,
fontSize: sizeHeadline6,
),
CalculatorButton(
text: '.',
color: AppColors.accent,
fontSize: sizeDisplay,
fontSize: sizeHeadline3,
),
CalculatorButton(
text: '=',
color: AppColors.accent,
fontSize: sizeHeadline1,
color: AppColors.danger,
fontSize: sizeHeadline4,
),
],
),
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/calculator_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CalculatorButton extends StatefulWidget {
CalculatorButton({
this.text,
this.color = AppColors.primaryText,
this.fontSize = sizeSubHead2,
this.fontSize = sizeSubtitle1,
});

@override
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/display_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class DisplayScreen extends StatelessWidget {

DisplayScreen({
this.leadingText,
this.fontSizeLeading = sizeCustom1,
this.fontSizeLeading = sizeHeadline1,
this.trailingText,
this.fontSizeTrailing = sizeSubHead2,
this.fontSizeTrailing = sizeSubtitle1,
});

@override
Expand Down
20 changes: 0 additions & 20 deletions lib/widgets/empty_data.dart

This file was deleted.

Loading

0 comments on commit ed9d2bc

Please sign in to comment.