From 1f5558bef4897ad819aa65980867ac5c7d6157b3 Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Mon, 21 Dec 2020 15:55:57 +0100 Subject: [PATCH] Changed instructions to a page instead of SimpleDialog, which was being annoying with state --- lib/main.dart | 4 + lib/pages/practice/PracticeSetupPage.dart | 6 +- .../instructions/YearInstructionDialog.dart | 43 ---- .../instructions/YearInstructionPage.dart | 224 ++++++++++++++++++ 4 files changed, 231 insertions(+), 46 deletions(-) delete mode 100644 lib/pages/practice/instructions/YearInstructionDialog.dart create mode 100644 lib/pages/practice/instructions/YearInstructionPage.dart diff --git a/lib/main.dart b/lib/main.dart index c7a4171..5915448 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -7,6 +7,7 @@ import 'package:ohthatsa/pages/practice/PracticePage.dart'; import 'package:ohthatsa/pages/MonthValuesPage.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; +import 'package:ohthatsa/pages/practice/instructions/YearInstructionPage.dart'; import 'package:rxdart/subjects.dart'; import 'package:flutter/services.dart'; @@ -123,6 +124,9 @@ class RouteGenerator { case "/notifications": { return MaterialPageRoute(builder: (context) => NotificationsPage()); } + case "/instructions/year": { + return MaterialPageRoute(builder: (context) => YearInstructionPage()); + } default: { return MaterialPageRoute(builder: (context) => YearsPage()); } diff --git a/lib/pages/practice/PracticeSetupPage.dart b/lib/pages/practice/PracticeSetupPage.dart index eddc78a..362d3fc 100644 --- a/lib/pages/practice/PracticeSetupPage.dart +++ b/lib/pages/practice/PracticeSetupPage.dart @@ -64,9 +64,9 @@ class _PracticeSetupState extends State { ); }, onLongPress: () { - showDialog( - context: context, - child: this.getInstructionDialog(practiceType) + Navigator.pushNamed( + context, + '/instructions/year' ); }, ), diff --git a/lib/pages/practice/instructions/YearInstructionDialog.dart b/lib/pages/practice/instructions/YearInstructionDialog.dart deleted file mode 100644 index d2f57ad..0000000 --- a/lib/pages/practice/instructions/YearInstructionDialog.dart +++ /dev/null @@ -1,43 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:ohthatsa/util/Months.dart'; - -TableRow getMonthTableRow(MapEntry month) { - return TableRow( - children: [ - TableCell( - child: Text( - month.key, - style: TextStyle(fontSize: 25), - textAlign: TextAlign.right - ) - ), - TableCell( - child: Text( - month.value.value.toString(), - style: TextStyle(fontSize: 25), - textAlign: TextAlign.center - ) - ) - ] - ); -} - -SimpleDialog getMonthInstructionDialog(){ - return SimpleDialog( - title: Text( - "Month Instructions", - style: TextStyle(fontSize: 25, color: Colors.blue), - ), - children: [ - Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text("Memorize these values for every month"), - Table( - children: Months.stringMap.entries.map(getMonthTableRow).toList() - ) - ] - ) - ], - ); -} \ No newline at end of file diff --git a/lib/pages/practice/instructions/YearInstructionPage.dart b/lib/pages/practice/instructions/YearInstructionPage.dart new file mode 100644 index 0000000..a0c7cde --- /dev/null +++ b/lib/pages/practice/instructions/YearInstructionPage.dart @@ -0,0 +1,224 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:numberpicker/numberpicker.dart'; + +import 'package:ohthatsa/other/AppDrawer.dart'; +import 'package:ohthatsa/util/DayCalculator.dart'; +import 'package:term_glyph/term_glyph.dart' as glyph; + +class YearInstructionPage extends StatefulWidget { + @override + _YearInstructionPageState createState() => _YearInstructionPageState(); +} + +class _YearInstructionPageState extends State { + int year; + int yy; + String centuriesString; + String yyString; + double yyDiv4; + int yyDiv4Floored; + int yearValue; + + @override + void initState(){ + super.initState(); + this.setYearValues(DateTime.now().year); + } + void setYearValues(newYear){ + year = newYear; + yy = year % 100; + centuriesString = (year ~/ 100).toString(); + yyString = year.toString().substring(2); + yyDiv4 = yy / 4; + yyDiv4Floored = yyDiv4.floor(); + yearValue = DayCalculator.getYearValue(year); + + setState(() {}); + } + static const formulaStyle = TextStyle( + fontSize: 20 + ); + static const formulaStyleU = TextStyle( + fontSize: 20, + decoration: TextDecoration.underline + ); + static const YYStyle = TextStyle( + color: Colors.green, + fontSize: 20 + ); + static const YYStyleU = TextStyle( + color: Colors.green, + fontSize: 20, + decoration: TextDecoration.underline + ); + static const pageNum = TextStyle( + color: Colors.grey, + fontSize: 20 + ); + static const pageNumCurrent = TextStyle( + color: Colors.blue, + fontSize: 20 + ); + @override + Widget build(BuildContext context) { + return Scaffold( + drawer: AppDrawer(), + appBar: AppBar( + title: Text("Year Instructions") + ), + body: PageView( + children: [ + Container( + padding: EdgeInsets.fromLTRB(0, 50, 0, 10), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + "Take only the last two digits: ", + style: TextStyle(fontSize: 25) + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "YY", + style: TextStyle( + color: Colors.grey, + fontSize: 25 + ) + ), + Text( + "YY", + style: YYStyle + ) + ], + ), + Text( + "Calculate:", + style: TextStyle(fontSize: 25) + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "(", + style: formulaStyle, + ), + Text( + "YY", + style: YYStyle + ), + Text( + " + floor(", + style: formulaStyle + ), + Text( + "YY", + style: YYStyle + ), + Text( + " / 4)) % 7", + style: formulaStyle + ), + ], + ), + Spacer(), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("1", style: pageNumCurrent), + Text(" - ", style: pageNum), + Text("2", style: pageNum), + ], + ) + ], + ) + ), + Container( + padding: EdgeInsets.fromLTRB(0, 0, 0, 10), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + NumberPicker.integer( + initialValue: year, + minValue: 1700, + maxValue: 2399, + onChanged: (newYear) => this.setYearValues(newYear) + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("For ", style: formulaStyle), + Text(centuriesString, style: formulaStyle), + Text(year.toString().substring(2), style: YYStyle), + Text(" our formula becomes: ", style: formulaStyle), + ], + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("(", style: formulaStyle), + Text(yyString, style: YYStyle), + Text(" + floor(", style: formulaStyle), + Text(yyString, style: YYStyleU), + Text(" / 4", style: formulaStyleU), + Text(")) % 7", style: formulaStyle), + ], + ), + Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("(", style: formulaStyle), + Text(yyString, style: YYStyle), + Text(" + ", style: formulaStyle), + Text("floor(" + yyDiv4.toString() + ")", style: formulaStyleU), + Text(") % 7", style: formulaStyle), + ], + ), + Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("(", style: formulaStyleU), + Text(yyString, style: YYStyleU), + Text(" + " + yyDiv4Floored.toString() + ")", style: formulaStyleU), + Text(" % 7", style: formulaStyle), + ], + ), + Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text((yy + yyDiv4Floored).toString(), style: formulaStyleU), + Text(" % 7", style: formulaStyleU), + ], + ), + Text(glyph.unicodeGlyphs.downArrow, style: TextStyle(fontSize: 15)), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("So the year value of " + year.toString() + " is: ", style: formulaStyle), + Text(yearValue.toString(), style: formulaStyleU), + ], + ), + Spacer(), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text("1", style: pageNum), + Text(" - ", style: pageNum), + Text("2", style: pageNumCurrent), + ], + ) + ] + ) + ) + ] + ) + ); + } +} \ No newline at end of file