Added leap year practice TODO change buttons for this?
This commit is contained in:
parent
29a9441e1d
commit
0176a2f333
4 changed files with 97 additions and 2 deletions
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:ohthatsa/pages/practice/PracticeSetup.dart';
|
import 'package:ohthatsa/pages/practice/PracticeSetup.dart';
|
||||||
import 'package:ohthatsa/pages/practice/PracticeThing.dart';
|
import 'package:ohthatsa/pages/practice/PracticeThing.dart';
|
||||||
import 'package:ohthatsa/pages/practice/PracticeThingCentury.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/pages/practice/PracticeThingMonth.dart';
|
||||||
import 'package:ohthatsa/AppDrawer.dart';
|
import 'package:ohthatsa/AppDrawer.dart';
|
||||||
import 'package:ohthatsa/pages/practice/PracticeType.dart';
|
import 'package:ohthatsa/pages/practice/PracticeType.dart';
|
||||||
|
@ -39,6 +40,10 @@ class _PracticeState extends State<PracticePage> {
|
||||||
this.practiceThing = PracticeThingCentury();
|
this.practiceThing = PracticeThingCentury();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case (PracticeType.leap): {
|
||||||
|
this.practiceThing = PracticeThingLeap();
|
||||||
|
break;
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,13 @@ class _PracticeSetupState extends State<PracticeSetupPage> {
|
||||||
child: Text("Leap"),
|
child: Text("Leap"),
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
textColor: Colors.white,
|
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("80%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)),
|
||||||
Text("70%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)),
|
Text("70%", textAlign: TextAlign.center, style: TextStyle(fontSize: 25)),
|
||||||
|
|
84
lib/pages/practice/PracticeThingLeap.dart
Normal file
84
lib/pages/practice/PracticeThingLeap.dart
Normal 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
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
enum PracticeType {
|
enum PracticeType {
|
||||||
month,
|
month,
|
||||||
century,
|
century,
|
||||||
year,
|
leap,
|
||||||
all
|
all
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue