More generalised practice stuff

This commit is contained in:
BroodjeAap 2020-11-03 20:03:49 +01:00
parent ba7c909ac4
commit 945360e0e2
7 changed files with 44 additions and 20 deletions

View file

@ -0,0 +1,10 @@
import 'package:ohthatsa/pages/practice/PracticeType.dart';
import 'package:ohthatsa/util/Months.dart';
class PracticeAnswer {
final int question;
final int answer;
final PracticeType practiceType;
PracticeAnswer(this.question, this.answer, this.practiceType);
}

View file

@ -3,9 +3,10 @@ import 'package:ohthatsa/pages/practice/PracticeSetup.dart';
import 'package:ohthatsa/pages/practice/PracticeThing.dart';
import 'package:ohthatsa/pages/practice/PracticeThingMonth.dart';
import 'package:ohthatsa/AppDrawer.dart';
import 'package:ohthatsa/pages/practice/PracticeType.dart';
import 'package:ohthatsa/util/Extensions.dart';
import 'month/MonthPracticeAnswer.dart';
import 'PracticeAnswer.dart';
class PracticePage extends StatefulWidget {
final PracticeSetup practiceSetup;
@ -28,7 +29,15 @@ class _PracticeState extends State<PracticePage> {
_PracticeState(PracticeSetup practiceSetup){
this._startCount = practiceSetup.count;
this._showCorrect = practiceSetup.showCorrect;
this.practiceThing = PracticeThingMonth();
switch(practiceSetup.practiceType){
case (PracticeType.month): {
this.practiceThing = PracticeThingMonth();
break;
}
default: {
//
}
}
}
Widget getAnswerRow(){

View file

@ -1,6 +1,9 @@
import 'package:ohthatsa/pages/practice/PracticeType.dart';
class PracticeSetup {
final int count;
final bool showCorrect;
final PracticeType practiceType;
PracticeSetup(this.count, this.showCorrect);
PracticeSetup(this.count, this.showCorrect, this.practiceType);
}

View file

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:numberpicker/numberpicker.dart';
import 'package:ohthatsa/AppDrawer.dart';
import 'package:ohthatsa/pages/practice/PracticeSetup.dart';
import 'package:ohthatsa/pages/practice/PracticeType.dart';
class PracticeSetupPage extends StatefulWidget {
@override
@ -77,7 +78,7 @@ class _PracticeSetupState extends State<PracticeSetupPage> {
Navigator.pushNamed(
context,
'/practice/month/practice',
arguments: PracticeSetup(_count, _showCorrect)
arguments: PracticeSetup(_count, _showCorrect, PracticeType.month)
);
},
),

View file

@ -2,12 +2,13 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:ohthatsa/pages/practice/PracticeThing.dart';
import 'package:ohthatsa/pages/practice/month/MonthPracticeAnswer.dart';
import 'package:ohthatsa/pages/practice/PracticeType.dart';
import 'file:///D:/dev/projects/ohthatsa/lib/pages/practice/PracticeAnswer.dart';
import 'package:ohthatsa/util/Months.dart';
class PracticeThingMonth extends PracticeThing {
final random = Random();
final List<MonthPracticeAnswer> answers = new List<MonthPracticeAnswer>();
final List<PracticeAnswer> answers = new List<PracticeAnswer>();
Month current;
PracticeThingMonth(){
@ -15,7 +16,7 @@ class PracticeThingMonth extends PracticeThing {
}
@override
bool answer(int answer) {
answers.add(MonthPracticeAnswer(current, answer));
answers.add(PracticeAnswer(current.i, answer, PracticeType.month));
return current.value == answer;
}
@ -25,7 +26,7 @@ class PracticeThingMonth extends PracticeThing {
}
List<bool> getBoolAnswers(){
return answers.map((answer) => answer.month.value == answer.answer).toList();
return answers.map((answer) => Months.getFromInt(answer.question).value == answer.answer).toList();
}
Text getAppBarTitleText(){
@ -46,8 +47,9 @@ class PracticeThingMonth extends PracticeThing {
Color color = Colors.red;
if(answers.length >= 1){
final answer = answers[answers.length - 1];
text = answer.month.toString() + (showCorrect ? ": ${answer.month.value}" : "");
if(answer.month.value == answer.answer){
final month = Months.getFromInt(answer.question);
text = month.toString() + (showCorrect ? ": ${month.value}" : "");
if(month.value == answer.answer){
color = Colors.green;
}
}
@ -64,8 +66,9 @@ class PracticeThingMonth extends PracticeThing {
Color color = Colors.red;
if(answers.length >= 2){
final answer = answers[answers.length - 2];
text = answer.month.toString() + (showCorrect ? ": ${answer.month.value}" : "");
if(answer.month.value == answer.answer){
final month = Months.getFromInt(answer.question);
text = month.toString() + (showCorrect ? ": ${month.value}" : "");
if(month.value == answer.answer){
color = Colors.green;
}
}

View file

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

View file

@ -1,8 +0,0 @@
import 'package:ohthatsa/util/Months.dart';
class MonthPracticeAnswer {
final Month month;
final int answer;
MonthPracticeAnswer(this.month, this.answer);
}