moved practice buttons to practice thing, so that leap practicething can only give two buttons (0 and 1)
This commit is contained in:
parent
fb66b095ab
commit
2a206c8960
8 changed files with 94 additions and 50 deletions
|
@ -18,10 +18,10 @@ class PracticePage extends StatefulWidget {
|
|||
this.practiceSetup
|
||||
);
|
||||
@override
|
||||
_PracticeState createState() => _PracticeState(practiceSetup);
|
||||
PracticePageState createState() => PracticePageState(practiceSetup);
|
||||
}
|
||||
|
||||
class _PracticeState extends State<PracticePage> {
|
||||
class PracticePageState extends State<PracticePage> {
|
||||
int _startCount = 0;
|
||||
bool _showCorrect = true;
|
||||
PracticeType practiceType;
|
||||
|
@ -31,37 +31,36 @@ class _PracticeState extends State<PracticePage> {
|
|||
int _correct = 0;
|
||||
int _incorrect = 0;
|
||||
|
||||
_PracticeState(PracticeSetup practiceSetup){
|
||||
PracticePageState(PracticeSetup practiceSetup){
|
||||
this._startCount = practiceSetup.count;
|
||||
this._showCorrect = practiceSetup.showCorrect;
|
||||
practiceType = practiceSetup.practiceType;
|
||||
switch(practiceType){
|
||||
case (PracticeType.month): {
|
||||
this.practiceThing = PracticeThingMonth();
|
||||
this.practiceThing = PracticeThingMonth(this);
|
||||
break;
|
||||
}
|
||||
case (PracticeType.year): {
|
||||
this.practiceThing = PracticeThingYear();
|
||||
this.practiceThing = PracticeThingYear(this);
|
||||
break;
|
||||
}
|
||||
case (PracticeType.century): {
|
||||
this.practiceThing = PracticeThingCentury();
|
||||
this.practiceThing = PracticeThingCentury(this);
|
||||
break;
|
||||
}
|
||||
case (PracticeType.leap): {
|
||||
this.practiceThing = PracticeThingLeap();
|
||||
this.practiceThing = PracticeThingLeap(this);
|
||||
break;
|
||||
}
|
||||
case (PracticeType.mod): {
|
||||
this.practiceThing = PracticeThingMod();
|
||||
this.practiceThing = PracticeThingMod(this);
|
||||
break;
|
||||
}
|
||||
case (PracticeType.all): {
|
||||
this.practiceThing = PracticeThingAll();
|
||||
this.practiceThing = PracticeThingAll(this);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -78,38 +77,6 @@ class _PracticeState extends State<PracticePage> {
|
|||
return Row(children: answerBoxes);
|
||||
}
|
||||
|
||||
Widget getButtons(){
|
||||
List<Widget> buttons = List<Widget>();
|
||||
for(int i in [1,2,3,4,5,6,-1,0,-1]){
|
||||
if (i == -1){
|
||||
buttons.add(Container());
|
||||
continue;
|
||||
}
|
||||
buttons.add(
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
checkAnswer(i);
|
||||
},
|
||||
color: Colors.blue,
|
||||
textColor: Colors.white,
|
||||
child: Text(
|
||||
i.toString(),
|
||||
style: TextStyle(fontSize: 30)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
return GridView.count(
|
||||
primary: false,
|
||||
crossAxisCount: 3,
|
||||
padding: EdgeInsets.fromLTRB(0, 20, 0, 20),
|
||||
mainAxisSpacing: 10,
|
||||
crossAxisSpacing: 10,
|
||||
shrinkWrap: true,
|
||||
children: buttons
|
||||
);
|
||||
}
|
||||
|
||||
SimpleDialog finishedPracticeDialog() {
|
||||
return SimpleDialog(
|
||||
title: Text(
|
||||
|
@ -203,7 +170,7 @@ class _PracticeState extends State<PracticePage> {
|
|||
practiceThing.getCurrentQuestionText()
|
||||
]
|
||||
),
|
||||
getButtons(),
|
||||
practiceThing.getButtons(),
|
||||
Align(
|
||||
alignment: FractionalOffset.bottomCenter,
|
||||
child: getAnswerRow()
|
||||
|
|
|
@ -3,11 +3,18 @@ import 'dart:math';
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:ohthatsa/pages/practice/PracticeAnswer.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticePage.dart';
|
||||
|
||||
abstract class PracticeThing {
|
||||
final random = Random();
|
||||
final List<PracticeAnswer> answers = new List<PracticeAnswer>();
|
||||
|
||||
final PracticePageState practicePageState;
|
||||
|
||||
PracticeThing(this.practicePageState){
|
||||
next();
|
||||
}
|
||||
|
||||
bool isCorrect(int answer);
|
||||
bool answer(int answer);
|
||||
void next();
|
||||
|
@ -16,4 +23,36 @@ abstract class PracticeThing {
|
|||
Text getCurrentQuestionText();
|
||||
Text getLastAnswerText(bool showCorrect);
|
||||
Text getSecondLastAnswerText(bool showCorrect);
|
||||
|
||||
Widget getButtons(){
|
||||
List<Widget> buttons = List<Widget>();
|
||||
for(int i in [1,2,3,4,5,6,-1,0,-1]){
|
||||
if (i == -1){
|
||||
buttons.add(Container());
|
||||
continue;
|
||||
}
|
||||
buttons.add(
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
practicePageState.checkAnswer(i);
|
||||
},
|
||||
color: Colors.blue,
|
||||
textColor: Colors.white,
|
||||
child: Text(
|
||||
i.toString(),
|
||||
style: TextStyle(fontSize: 30)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
return GridView.count(
|
||||
primary: false,
|
||||
crossAxisCount: 3,
|
||||
padding: EdgeInsets.fromLTRB(0, 20, 0, 20),
|
||||
mainAxisSpacing: 10,
|
||||
crossAxisSpacing: 10,
|
||||
shrinkWrap: true,
|
||||
children: buttons
|
||||
);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:intl/intl.dart';
|
||||
import 'package:flutter/src/widgets/text.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticeAnswer.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticePage.dart';
|
||||
import 'package:ohthatsa/pages/practice/thing/PracticeThing.dart';
|
||||
|
||||
class PracticeThingAll extends PracticeThing {
|
||||
|
@ -23,7 +24,7 @@ class PracticeThingAll extends PracticeThing {
|
|||
DateTime.december
|
||||
];
|
||||
|
||||
PracticeThingAll() {
|
||||
PracticeThingAll(PracticePageState practicePageState) : super(practicePageState) {
|
||||
next();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,14 @@ import 'dart:ui';
|
|||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticeAnswer.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticePage.dart';
|
||||
import 'package:ohthatsa/pages/practice/thing/PracticeThing.dart';
|
||||
import 'package:ohthatsa/util/DayCalculator.dart';
|
||||
|
||||
class PracticeThingCentury extends PracticeThing {
|
||||
int current;
|
||||
|
||||
PracticeThingCentury(){
|
||||
PracticeThingCentury(PracticePageState practicePageState) : super(practicePageState) {
|
||||
next();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,13 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter/src/widgets/text.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticeAnswer.dart';
|
||||
import 'package:ohthatsa/pages/practice/thing/PracticeThing.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticeType.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticePage.dart';
|
||||
import 'package:ohthatsa/util/DayCalculator.dart';
|
||||
|
||||
class PracticeThingLeap extends PracticeThing {
|
||||
int current;
|
||||
|
||||
PracticeThingLeap(){
|
||||
PracticeThingLeap(PracticePageState practicePageState) : super(practicePageState) {
|
||||
next();
|
||||
}
|
||||
|
||||
|
@ -87,4 +87,37 @@ class PracticeThingLeap extends PracticeThing {
|
|||
)
|
||||
);
|
||||
}
|
||||
|
||||
Widget getButtons(){
|
||||
return Container(
|
||||
padding: EdgeInsets.fromLTRB(0, 20, 0, 20),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
practicePageState.checkAnswer(0);
|
||||
},
|
||||
color: Colors.blue,
|
||||
textColor: Colors.white,
|
||||
child: Text(
|
||||
"0",
|
||||
style: TextStyle(fontSize: 30)
|
||||
)
|
||||
),
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
practicePageState.checkAnswer(1);
|
||||
},
|
||||
color: Colors.blue,
|
||||
textColor: Colors.white,
|
||||
child: Text(
|
||||
"1",
|
||||
style: TextStyle(fontSize: 30)
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,12 +1,13 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticeAnswer.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticePage.dart';
|
||||
import 'package:ohthatsa/pages/practice/thing/PracticeThing.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticeType.dart';
|
||||
|
||||
class PracticeThingMod extends PracticeThing {
|
||||
int current;
|
||||
|
||||
PracticeThingMod() {
|
||||
PracticeThingMod(PracticePageState practicePageState) : super(practicePageState) {
|
||||
next();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticePage.dart';
|
||||
import 'package:ohthatsa/pages/practice/thing/PracticeThing.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticeType.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticeAnswer.dart';
|
||||
|
@ -11,7 +12,7 @@ class PracticeThingMonth extends PracticeThing {
|
|||
|
||||
Month current;
|
||||
|
||||
PracticeThingMonth(){
|
||||
PracticeThingMonth(PracticePageState practicePageState) : super(practicePageState) {
|
||||
next();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticeAnswer.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticePage.dart';
|
||||
import 'package:ohthatsa/pages/practice/thing/PracticeThing.dart';
|
||||
import 'package:ohthatsa/util/DayCalculator.dart';
|
||||
|
||||
class PracticeThingYear extends PracticeThing {
|
||||
int current;
|
||||
|
||||
PracticeThingYear() {
|
||||
PracticeThingYear(PracticePageState practicePageState) : super(practicePageState) {
|
||||
next();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue