diff --git a/lib/pages/practice/PracticePage.dart b/lib/pages/practice/PracticePage.dart index 0c46b40..8546bfd 100644 --- a/lib/pages/practice/PracticePage.dart +++ b/lib/pages/practice/PracticePage.dart @@ -3,6 +3,7 @@ import 'package:ohthatsa/pages/practice/PracticeSetup.dart'; import 'package:ohthatsa/pages/practice/PracticeThing.dart'; import 'package:ohthatsa/pages/practice/PracticeThingCentury.dart'; import 'package:ohthatsa/pages/practice/PracticeThingLeap.dart'; +import 'package:ohthatsa/pages/practice/PracticeThingMod.dart'; import 'package:ohthatsa/pages/practice/PracticeThingMonth.dart'; import 'package:ohthatsa/AppDrawer.dart'; import 'package:ohthatsa/pages/practice/PracticeType.dart'; @@ -44,6 +45,10 @@ class _PracticeState extends State { this.practiceThing = PracticeThingLeap(); break; } + case (PracticeType.mod): { + this.practiceThing = PracticeThingMod(); + break; + } default: { // } diff --git a/lib/pages/practice/PracticeSetupPage.dart b/lib/pages/practice/PracticeSetupPage.dart index 994699c..3e4b23f 100644 --- a/lib/pages/practice/PracticeSetupPage.dart +++ b/lib/pages/practice/PracticeSetupPage.dart @@ -107,23 +107,42 @@ class _PracticeSetupState extends State { ] ), TableRow( - children: [ - FlatButton( - child: Text("Leap"), - color: Colors.blue, - textColor: Colors.white, - onPressed: () { - Navigator.pushNamed( - context, - '/practice/practice', - arguments: PracticeSetup(_count, _showCorrect, PracticeType.leap) - ); - }, - ), - Text("80%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)), - Text("70%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)), - Text("50%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)) - ] + children: [ + FlatButton( + child: Text("Leap"), + color: Colors.blue, + textColor: Colors.white, + onPressed: () { + Navigator.pushNamed( + context, + '/practice/practice', + arguments: PracticeSetup(_count, _showCorrect, PracticeType.leap) + ); + }, + ), + Text("80%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)), + Text("70%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)), + Text("50%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)) + ] + ), + TableRow( + children: [ + FlatButton( + child: Text("Modulo 7"), + color: Colors.blue, + textColor: Colors.white, + onPressed: () { + Navigator.pushNamed( + context, + '/practice/practice', + arguments: PracticeSetup(_count, _showCorrect, PracticeType.mod) + ); + }, + ), + Text("80%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)), + Text("70%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)), + Text("50%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)) + ] ), TableRow( children: [ diff --git a/lib/pages/practice/PracticeThingMod.dart b/lib/pages/practice/PracticeThingMod.dart new file mode 100644 index 0000000..eeeffce --- /dev/null +++ b/lib/pages/practice/PracticeThingMod.dart @@ -0,0 +1,84 @@ +import 'package:flutter/material.dart'; +import 'package:ohthatsa/pages/practice/PracticeAnswer.dart'; +import 'package:ohthatsa/pages/practice/PracticeThing.dart'; +import 'package:ohthatsa/pages/practice/PracticeType.dart'; + +class PracticeThingMod extends PracticeThing { + int current; + + PracticeThingMod() { + next(); + } + + @override + bool answer(int answer) { + answers.add(PracticeAnswer(current, answer, PracticeType.mod)); + final correctAnswer = current % 7; + return answer == correctAnswer; + } + + @override + void next() { + current = random.nextInt(141); + } + + @override + Text getAppBarTitleText() { + return Text("Practicing Modulo"); + } + + @override + List getBoolAnswers() { + return answers.map((answer) => + answer.question % 7 == answer.answer + ).toList(); + } + + Text getCurrentQuestionText(){ + return Text( + current.toString(), + style: TextStyle( + fontSize: 30 + ) + ); + } + + Text getLastAnswerText(bool showCorrect){ + String text = "-"; + Color color = Colors.red; + if(answers.length >= 1){ + final answer = answers[answers.length - 1]; + final correctAnswer = answer.question % 7; + text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : ""); + if(answer.answer == correctAnswer){ + color = Colors.green; + } + } + return Text( + text, + style: TextStyle( + fontSize: 15, + color: color + ) + ); + } + Text getSecondLastAnswerText(bool showCorrect){ + String text = "-"; + Color color = Colors.red; + if(answers.length >= 2){ + final answer = answers[answers.length - 2]; + final correctAnswer = answer.question % 7; + text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : ""); + if(answer.answer == correctAnswer){ + color = Colors.green; + } + } + return Text( + text, + style: TextStyle( + fontSize: 10, + color: color + ) + ); + } +} \ No newline at end of file diff --git a/lib/pages/practice/PracticeType.dart b/lib/pages/practice/PracticeType.dart index f115e05..c197909 100644 --- a/lib/pages/practice/PracticeType.dart +++ b/lib/pages/practice/PracticeType.dart @@ -2,5 +2,6 @@ enum PracticeType { month, century, leap, + mod, all } \ No newline at end of file