More generalised practice stuff
This commit is contained in:
parent
ba7c909ac4
commit
945360e0e2
7 changed files with 44 additions and 20 deletions
10
lib/pages/practice/PracticeAnswer.dart
Normal file
10
lib/pages/practice/PracticeAnswer.dart
Normal 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);
|
||||||
|
}
|
|
@ -3,9 +3,10 @@ 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/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/util/Extensions.dart';
|
import 'package:ohthatsa/util/Extensions.dart';
|
||||||
|
|
||||||
import 'month/MonthPracticeAnswer.dart';
|
import 'PracticeAnswer.dart';
|
||||||
|
|
||||||
class PracticePage extends StatefulWidget {
|
class PracticePage extends StatefulWidget {
|
||||||
final PracticeSetup practiceSetup;
|
final PracticeSetup practiceSetup;
|
||||||
|
@ -28,7 +29,15 @@ class _PracticeState extends State<PracticePage> {
|
||||||
_PracticeState(PracticeSetup practiceSetup){
|
_PracticeState(PracticeSetup practiceSetup){
|
||||||
this._startCount = practiceSetup.count;
|
this._startCount = practiceSetup.count;
|
||||||
this._showCorrect = practiceSetup.showCorrect;
|
this._showCorrect = practiceSetup.showCorrect;
|
||||||
this.practiceThing = PracticeThingMonth();
|
switch(practiceSetup.practiceType){
|
||||||
|
case (PracticeType.month): {
|
||||||
|
this.practiceThing = PracticeThingMonth();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget getAnswerRow(){
|
Widget getAnswerRow(){
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
|
import 'package:ohthatsa/pages/practice/PracticeType.dart';
|
||||||
|
|
||||||
class PracticeSetup {
|
class PracticeSetup {
|
||||||
final int count;
|
final int count;
|
||||||
final bool showCorrect;
|
final bool showCorrect;
|
||||||
|
final PracticeType practiceType;
|
||||||
|
|
||||||
PracticeSetup(this.count, this.showCorrect);
|
PracticeSetup(this.count, this.showCorrect, this.practiceType);
|
||||||
}
|
}
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:numberpicker/numberpicker.dart';
|
import 'package:numberpicker/numberpicker.dart';
|
||||||
import 'package:ohthatsa/AppDrawer.dart';
|
import 'package:ohthatsa/AppDrawer.dart';
|
||||||
import 'package:ohthatsa/pages/practice/PracticeSetup.dart';
|
import 'package:ohthatsa/pages/practice/PracticeSetup.dart';
|
||||||
|
import 'package:ohthatsa/pages/practice/PracticeType.dart';
|
||||||
|
|
||||||
class PracticeSetupPage extends StatefulWidget {
|
class PracticeSetupPage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
|
@ -77,7 +78,7 @@ class _PracticeSetupState extends State<PracticeSetupPage> {
|
||||||
Navigator.pushNamed(
|
Navigator.pushNamed(
|
||||||
context,
|
context,
|
||||||
'/practice/month/practice',
|
'/practice/month/practice',
|
||||||
arguments: PracticeSetup(_count, _showCorrect)
|
arguments: PracticeSetup(_count, _showCorrect, PracticeType.month)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
|
@ -2,12 +2,13 @@ import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:ohthatsa/pages/practice/PracticeThing.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';
|
import 'package:ohthatsa/util/Months.dart';
|
||||||
|
|
||||||
class PracticeThingMonth extends PracticeThing {
|
class PracticeThingMonth extends PracticeThing {
|
||||||
final random = Random();
|
final random = Random();
|
||||||
final List<MonthPracticeAnswer> answers = new List<MonthPracticeAnswer>();
|
final List<PracticeAnswer> answers = new List<PracticeAnswer>();
|
||||||
Month current;
|
Month current;
|
||||||
|
|
||||||
PracticeThingMonth(){
|
PracticeThingMonth(){
|
||||||
|
@ -15,7 +16,7 @@ class PracticeThingMonth extends PracticeThing {
|
||||||
}
|
}
|
||||||
@override
|
@override
|
||||||
bool answer(int answer) {
|
bool answer(int answer) {
|
||||||
answers.add(MonthPracticeAnswer(current, answer));
|
answers.add(PracticeAnswer(current.i, answer, PracticeType.month));
|
||||||
return current.value == answer;
|
return current.value == answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ class PracticeThingMonth extends PracticeThing {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<bool> getBoolAnswers(){
|
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(){
|
Text getAppBarTitleText(){
|
||||||
|
@ -46,8 +47,9 @@ class PracticeThingMonth extends PracticeThing {
|
||||||
Color color = Colors.red;
|
Color color = Colors.red;
|
||||||
if(answers.length >= 1){
|
if(answers.length >= 1){
|
||||||
final answer = answers[answers.length - 1];
|
final answer = answers[answers.length - 1];
|
||||||
text = answer.month.toString() + (showCorrect ? ": ${answer.month.value}" : "");
|
final month = Months.getFromInt(answer.question);
|
||||||
if(answer.month.value == answer.answer){
|
text = month.toString() + (showCorrect ? ": ${month.value}" : "");
|
||||||
|
if(month.value == answer.answer){
|
||||||
color = Colors.green;
|
color = Colors.green;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,8 +66,9 @@ class PracticeThingMonth extends PracticeThing {
|
||||||
Color color = Colors.red;
|
Color color = Colors.red;
|
||||||
if(answers.length >= 2){
|
if(answers.length >= 2){
|
||||||
final answer = answers[answers.length - 2];
|
final answer = answers[answers.length - 2];
|
||||||
text = answer.month.toString() + (showCorrect ? ": ${answer.month.value}" : "");
|
final month = Months.getFromInt(answer.question);
|
||||||
if(answer.month.value == answer.answer){
|
text = month.toString() + (showCorrect ? ": ${month.value}" : "");
|
||||||
|
if(month.value == answer.answer){
|
||||||
color = Colors.green;
|
color = Colors.green;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
lib/pages/practice/PracticeType.dart
Normal file
6
lib/pages/practice/PracticeType.dart
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
enum PracticeType {
|
||||||
|
month,
|
||||||
|
century,
|
||||||
|
year,
|
||||||
|
all
|
||||||
|
}
|
|
@ -1,8 +0,0 @@
|
||||||
import 'package:ohthatsa/util/Months.dart';
|
|
||||||
|
|
||||||
class MonthPracticeAnswer {
|
|
||||||
final Month month;
|
|
||||||
final int answer;
|
|
||||||
|
|
||||||
MonthPracticeAnswer(this.month, this.answer);
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue