Added leap year practice TODO change buttons for this?

This commit is contained in:
BroodjeAap 2020-11-03 20:41:31 +01:00
parent 29a9441e1d
commit 0176a2f333
4 changed files with 97 additions and 2 deletions

View file

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
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/PracticeThingMonth.dart';
import 'package:ohthatsa/AppDrawer.dart';
import 'package:ohthatsa/pages/practice/PracticeType.dart';
@ -39,6 +40,10 @@ class _PracticeState extends State<PracticePage> {
this.practiceThing = PracticeThingCentury();
break;
}
case (PracticeType.leap): {
this.practiceThing = PracticeThingLeap();
break;
}
default: {
//
}

View file

@ -112,7 +112,13 @@ class _PracticeSetupState extends State<PracticeSetupPage> {
child: Text("Leap"),
color: Colors.blue,
textColor: Colors.white,
onPressed: () {},
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)),

View file

@ -0,0 +1,84 @@
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/text.dart';
import 'package:ohthatsa/pages/practice/PracticeAnswer.dart';
import 'package:ohthatsa/pages/practice/PracticeThing.dart';
import 'package:ohthatsa/pages/practice/PracticeType.dart';
import 'package:ohthatsa/util/DayCalculator.dart';
class PracticeThingLeap extends PracticeThing {
int current;
PracticeThingLeap(){
next();
}
@override
bool answer(int answer) {
answers.add(PracticeAnswer(current, answer, PracticeType.month));
final correctAnswer = DayCalculator.isLeapYear(current);
return (answer != 0) == correctAnswer;
}
@override
void next() {
current = random.nextInt(10000);
}
List<bool> getBoolAnswers(){
return answers.map((answer) =>
(answer.answer != 0) == DayCalculator.isLeapYear(answer.question)
).toList();
}
Text getAppBarTitleText(){
return Text("Practicing Leap Years");
}
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 = DayCalculator.isLeapYear(answer.question);
text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : "");
if((answer.answer != 0) == 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 = DayCalculator.isLeapYear(answer.question);
text = answer.question.toString() + (showCorrect ? ": $correctAnswer" : "");
if((answer.answer != 0) == correctAnswer){
color = Colors.green;
}
}
return Text(
text,
style: TextStyle(
fontSize: 10,
color: color
)
);
}
}

View file

@ -1,6 +1,6 @@
enum PracticeType {
month,
century,
year,
leap,
all
}