diff --git a/lib/main.dart b/lib/main.dart index d132f44..9379fdf 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -13,7 +13,7 @@ void main() async { final appDirectory = await path.getApplicationDocumentsDirectory(); Hive.init(appDirectory.path); Hive.registerAdapter(RecordAdapter()); - await Hive.openBox('records'); + await Hive.openBox(boxRecord); runApp( MultiProvider( providers: [ diff --git a/lib/models/record.dart b/lib/models/record.dart index d3eb0b5..dc36d98 100644 --- a/lib/models/record.dart +++ b/lib/models/record.dart @@ -2,6 +2,8 @@ import 'package:hive/hive.dart'; part 'record.g.dart'; +const String boxRecord = 'record'; + @HiveType(typeId: 0) class Record { @HiveField(0) diff --git a/lib/pages/calculator_page.dart b/lib/pages/calculator_page.dart index c929125..b90f719 100644 --- a/lib/pages/calculator_page.dart +++ b/lib/pages/calculator_page.dart @@ -21,9 +21,8 @@ class _CalculatorPageState extends State { Widget build(BuildContext context) { return AnnotatedRegion( value: SystemUiOverlayStyle.light.copyWith( - statusBarColor: Colors.transparent, - systemNavigationBarColor: AppColors.darkShadow - ), + statusBarColor: Colors.transparent, + systemNavigationBarColor: AppColors.darkShadow), child: Material( color: AppColors.baseColor, child: Padding( @@ -46,10 +45,12 @@ class _CalculatorPageState extends State { Hero( tag: 'iconButton', child: CustomIconButton( - Icons.history, + icon: Icons.history, size: 25.0, - onPressed: () => - Navigator.pushNamed(context, RecordsPage.id), + onPressed: () => Navigator.pushNamed( + context, + RecordsPage.id, + ), ), ), ], @@ -67,7 +68,7 @@ class _CalculatorPageState extends State { @override void dispose() { - Hive.box('records') + Hive.box(boxRecord) ..compact() ..close(); super.dispose(); diff --git a/lib/pages/records_page.dart b/lib/pages/records_page.dart index eca1a5d..1b2a8ee 100644 --- a/lib/pages/records_page.dart +++ b/lib/pages/records_page.dart @@ -9,7 +9,7 @@ import 'package:neucalcu/widgets/record_container.dart'; class RecordsPage extends StatelessWidget { static const String id = '/records'; - final recordBox = Hive.box('records'); + final recordBox = Hive.box(boxRecord); @override Widget build(BuildContext context) { @@ -32,7 +32,7 @@ class RecordsPage extends StatelessWidget { child: Hero( tag: 'iconButton', child: CustomIconButton( - Icons.arrow_back_ios, + icon: Icons.arrow_back_ios, onPressed: () => Navigator.pop(context), ), ), @@ -40,14 +40,14 @@ class RecordsPage extends StatelessWidget { Text( 'Record History', style: TextStyle( - color: Colors.white54, + color: AppColors.primaryText, fontSize: sizeSubHead2, ), ), Positioned( right: 0, child: CustomIconButton( - Icons.delete, + icon: Icons.delete, onPressed: () { recordBox..clear(); Navigator.pop(context); diff --git a/lib/providers/calculate.dart b/lib/providers/calculate.dart index c1adfd6..e9a42cd 100644 --- a/lib/providers/calculate.dart +++ b/lib/providers/calculate.dart @@ -50,26 +50,25 @@ class Calculate with ChangeNotifier { _calculateExpression(isPreviewActive: false); if (!(_result == 'Syntax Error')) { - _saveRecord(); - _equation = _result; + String equation = _equation; + String answer = _equation = _result; _result = 'Answer'; + _saveRecord(answer: answer, equation: equation); } } - void _saveRecord() { + _saveRecord({String answer, String equation}) { DateTime now = new DateTime.now(); DateFormat formatter = new DateFormat('MMMM dd, yyyy'); String formattedDate = formatter.format(now); Record record = Record( - answer: _result, - equation: _equation, + answer: answer, + equation: equation, date: formattedDate, ); - if (!(_result == 'Answer')) { - Hive.box('records').add(record); - } + Hive.box(boxRecord).add(record); } _calculateExpression({bool isPreviewActive}) { diff --git a/lib/widgets/custom_icon_button.dart b/lib/widgets/custom_icon_button.dart index 2cbfaf0..dd42cad 100644 --- a/lib/widgets/custom_icon_button.dart +++ b/lib/widgets/custom_icon_button.dart @@ -7,7 +7,7 @@ class CustomIconButton extends StatelessWidget { final double size; final Function onPressed; - CustomIconButton(this.icon, {this.size = 20.0, @required this.onPressed}); + CustomIconButton({this.icon, this.size = 20.0, @required this.onPressed}); static const double _buttonSize = 40.0; diff --git a/pubspec.yaml b/pubspec.yaml index 7c77b93..8b157b9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A new Flutter application. publish_to: 'none' -version: 1.0.1+2 +version: 1.1.0+3 environment: sdk: ">=2.7.0 <3.0.0"