From d71b02e9c9a3d766c7249eb58aa282f04ecc8085 Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Sat, 17 Oct 2020 16:33:57 +0200 Subject: [PATCH] added simple graphics to the practice page --- .../practice/month/MonthPracticeAnswer.dart | 6 +++ .../practice/month/MonthPracticePage.dart | 50 +++++++++++++++---- 2 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 lib/pages/practice/month/MonthPracticeAnswer.dart diff --git a/lib/pages/practice/month/MonthPracticeAnswer.dart b/lib/pages/practice/month/MonthPracticeAnswer.dart new file mode 100644 index 0000000..7fa1ab1 --- /dev/null +++ b/lib/pages/practice/month/MonthPracticeAnswer.dart @@ -0,0 +1,6 @@ +class MonthPracticeAnswer { + final int month; + final int answer; + + MonthPracticeAnswer(this.month, this.answer); +} \ No newline at end of file diff --git a/lib/pages/practice/month/MonthPracticePage.dart b/lib/pages/practice/month/MonthPracticePage.dart index e88b6c0..4ec6c89 100644 --- a/lib/pages/practice/month/MonthPracticePage.dart +++ b/lib/pages/practice/month/MonthPracticePage.dart @@ -4,12 +4,15 @@ import 'package:ohthatsa/util/DayCalculator.dart'; import 'package:ohthatsa/AppDrawer.dart'; import "dart:math"; +import 'MonthPracticeAnswer.dart'; + class MonthPracticePage extends StatefulWidget { @override _MonthPracticeState createState() => _MonthPracticeState(); } class _MonthPracticeState extends State { + int _startCount = 0; int _count = 0; int _correct = 0; int _incorrect = 0; @@ -29,15 +32,33 @@ class _MonthPracticeState extends State { "December" ]; String _month = _months[_random.nextInt(_months.length)]; + List answers = new List(); - + Widget getAnswerRow(){ + List answerBoxes = new List(); + double screenWidth = MediaQuery.of(context).size.width; + for(MonthPracticeAnswer answer in answers){ + Color c = Colors.green; + if(answer.month != answer.answer){ + c = Colors.red; + } + answerBoxes.add( + new SizedBox( + width: screenWidth / _startCount, + height: 100, + child: new DecoratedBox( + decoration: BoxDecoration(color: c) + ) + ) + ); + } + return new Row(children: answerBoxes); + } @override Widget build(BuildContext context) { MonthPracticeSetup setup = ModalRoute.of(context).settings.arguments; - if(_count == 0) { - _count = setup.count; - } + _startCount = setup.count; return Scaffold( drawer: AppDrawer(), appBar: AppBar( @@ -55,7 +76,7 @@ class _MonthPracticeState extends State { "Correct: " + _correct.toString() ), new Text( - _count.toString() + " left" + (_startCount - _count).toString() + " left" ), new Text( "Incorrect: " + _incorrect.toString() @@ -131,6 +152,10 @@ class _MonthPracticeState extends State { child: new Text("0") ) ] + ), + new Align( + alignment: FractionalOffset.bottomCenter, + child: getAnswerRow() ) ], ) @@ -138,18 +163,21 @@ class _MonthPracticeState extends State { ); } - void checkMonth(int value){ - if(value == DayCalculator.getMonthValueByString(_month)){ + void checkMonth(int answer){ + int month = DayCalculator.getMonthValueByString(_month); + if(answer == month){ _correct += 1; } else { _incorrect += 1; } - _count -= 1; + _count += 1; + answers.add(new MonthPracticeAnswer(month, answer)); + if((_startCount - _count) == 0) { + Navigator.pop(context); + return; + } setState(() => { _month = _months[_random.nextInt(_months.length)] }); - if(_count == 0) { - Navigator.pop(context); - } } } \ No newline at end of file