From 11a6d765c1f2cc00b531208921993ed5857cea5f Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Sat, 3 Oct 2020 17:04:31 +0200 Subject: [PATCH] Added simple practice page for month values --- lib/AppDrawer.dart | 7 ++ lib/MonthPracticePage.dart | 145 ++++++++++++++++++++++++++++++++ lib/MonthPracticeSetupPage.dart | 45 ++++++++++ lib/main.dart | 4 + 4 files changed, 201 insertions(+) create mode 100644 lib/MonthPracticePage.dart create mode 100644 lib/MonthPracticeSetupPage.dart diff --git a/lib/AppDrawer.dart b/lib/AppDrawer.dart index a0a648a..4c17c1c 100644 --- a/lib/AppDrawer.dart +++ b/lib/AppDrawer.dart @@ -25,6 +25,13 @@ class AppDrawer extends StatelessWidget { Navigator.pushNamed(context, "/years"); } ), + ListTile( + title: Text("Practice Months"), + onTap: () { + Navigator.pop(context); + Navigator.pushNamed(context, "/practice/month/setup"); + } + ), ], ) ); diff --git a/lib/MonthPracticePage.dart b/lib/MonthPracticePage.dart new file mode 100644 index 0000000..c4deb5c --- /dev/null +++ b/lib/MonthPracticePage.dart @@ -0,0 +1,145 @@ +import 'package:flutter/material.dart'; +import 'package:numberpicker/numberpicker.dart'; +import 'package:ohthatsa/DayCalculator.dart'; +import 'AppDrawer.dart'; +import "dart:math"; + +class MonthPracticePage extends StatefulWidget { + @override + _MonthPracticeState createState() => _MonthPracticeState(); +} + +class _MonthPracticeState extends State { + int count = 0; + int correct = 0; + int incorrect = 0; + static final _random = new Random(); + static List _months = [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December" + ]; + String _month = _months[_random.nextInt(_months.length)]; + + + + @override + Widget build(BuildContext context) { + return Scaffold( + drawer: AppDrawer(), + appBar: AppBar( + title: Text("Practicing months"), + ), + body: Center( + child: new Column( + children: [ + new Container( + padding: EdgeInsets.all(20), + child: new Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + + children: [ + new Text( + "Correct: " + correct.toString() + ), + new Text( + "Incorrect: " + incorrect.toString() + ) + ], + ) + ), + new Text( + _month + ), + new GridView.count( + primary: false, + crossAxisCount: 3, + padding: EdgeInsets.all(50), + mainAxisSpacing: 10, + crossAxisSpacing: 10, + shrinkWrap: true, + children: [ + new FlatButton( + onPressed: () { + checkMonth(1); + }, + color: Colors.blue, + textColor: Colors.white, + child: new Text("1") + ), + new FlatButton( + onPressed: () { + checkMonth(2); + }, + color: Colors.blue, + textColor: Colors.white, + child: new Text("2") + ), + new FlatButton( + onPressed: () { + checkMonth(3); + }, + color: Colors.blue, + textColor: Colors.white, + child: new Text("3") + ), + new FlatButton( + onPressed: () { + checkMonth(4); + }, + color: Colors.blue, + textColor: Colors.white, + child: new Text("4") + ), + new FlatButton( + onPressed: () { + checkMonth(5); + }, + color: Colors.blue, + textColor: Colors.white, + child: new Text("5") + ), + new FlatButton( + onPressed: () { + checkMonth(6); + }, + color: Colors.blue, + textColor: Colors.white, + child: new Text("6") + ), + new FlatButton( + onPressed: () { + checkMonth(0); + }, + color: Colors.blue, + textColor: Colors.white, + child: new Text("0") + ) + ] + ) + ], + ) + ) + ); + } + + void checkMonth(int value){ + if(value == DayCalculator.getMonthValueByString(_month)){ + correct += 1; + } else { + incorrect += 1; + } + setState(() => + _month = _months[_random.nextInt(_months.length)] + ); + } +} \ No newline at end of file diff --git a/lib/MonthPracticeSetupPage.dart b/lib/MonthPracticeSetupPage.dart new file mode 100644 index 0000000..6a9a3d1 --- /dev/null +++ b/lib/MonthPracticeSetupPage.dart @@ -0,0 +1,45 @@ +import 'package:flutter/material.dart'; +import 'package:numberpicker/numberpicker.dart'; +import 'AppDrawer.dart'; + +class MonthPracticeSetupPage extends StatefulWidget { + @override + _MonthPracticeSetupState createState() => _MonthPracticeSetupState(); +} + +class _MonthPracticeSetupState extends State { + int _number = 5; + @override + Widget build(BuildContext context){ + return Scaffold( + drawer: AppDrawer(), + appBar: AppBar( + title: Text("Practice Months"), + ), + body: Center( + child: new Column( + children: [ + new Text("How many times would you like to practice?"), + new NumberPicker.integer( + initialValue: _number, + minValue: 1, + maxValue: 1000000, + onChanged: (newNumber) => + setState(() => _number = newNumber), + ), + new FlatButton( + onPressed: () { + Navigator.pushNamed(context, '/practice/month/practice'); + }, + child: new Text("Start!"), + color: Colors.blue, + textColor: Colors.white, + padding: EdgeInsets.all(8.0) + ) + ] + ) + ) + ); + } +} + diff --git a/lib/main.dart b/lib/main.dart index 15f31ac..227dc15 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; +import 'package:ohthatsa/MonthPracticeSetupPage.dart'; import 'package:ohthatsa/YearsPage.dart'; +import 'MonthPracticePage.dart'; import 'MonthValuesPage.dart'; void main() { @@ -17,6 +19,8 @@ class OhThatsA extends StatelessWidget { routes: { '/monthValues': (context) => MonthValuesPage(), '/years': (context) => YearsPage(), + '/practice/month/setup': (context) => MonthPracticeSetupPage(), + '/practice/month/practice': (context) => MonthPracticePage(), } ); }