added simple graphics to the practice page
This commit is contained in:
parent
65766771a6
commit
d71b02e9c9
2 changed files with 45 additions and 11 deletions
6
lib/pages/practice/month/MonthPracticeAnswer.dart
Normal file
6
lib/pages/practice/month/MonthPracticeAnswer.dart
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
class MonthPracticeAnswer {
|
||||||
|
final int month;
|
||||||
|
final int answer;
|
||||||
|
|
||||||
|
MonthPracticeAnswer(this.month, this.answer);
|
||||||
|
}
|
|
@ -4,12 +4,15 @@ import 'package:ohthatsa/util/DayCalculator.dart';
|
||||||
import 'package:ohthatsa/AppDrawer.dart';
|
import 'package:ohthatsa/AppDrawer.dart';
|
||||||
import "dart:math";
|
import "dart:math";
|
||||||
|
|
||||||
|
import 'MonthPracticeAnswer.dart';
|
||||||
|
|
||||||
class MonthPracticePage extends StatefulWidget {
|
class MonthPracticePage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_MonthPracticeState createState() => _MonthPracticeState();
|
_MonthPracticeState createState() => _MonthPracticeState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MonthPracticeState extends State<MonthPracticePage> {
|
class _MonthPracticeState extends State<MonthPracticePage> {
|
||||||
|
int _startCount = 0;
|
||||||
int _count = 0;
|
int _count = 0;
|
||||||
int _correct = 0;
|
int _correct = 0;
|
||||||
int _incorrect = 0;
|
int _incorrect = 0;
|
||||||
|
@ -29,15 +32,33 @@ class _MonthPracticeState extends State<MonthPracticePage> {
|
||||||
"December"
|
"December"
|
||||||
];
|
];
|
||||||
String _month = _months[_random.nextInt(_months.length)];
|
String _month = _months[_random.nextInt(_months.length)];
|
||||||
|
List<MonthPracticeAnswer> answers = new List<MonthPracticeAnswer>();
|
||||||
|
|
||||||
|
Widget getAnswerRow(){
|
||||||
|
List<Widget> answerBoxes = new List<Widget>();
|
||||||
|
double screenWidth = MediaQuery.of(context).size.width;
|
||||||
|
for(MonthPracticeAnswer answer in answers){
|
||||||
|
Color c = Colors.green;
|
||||||
|
if(answer.month != answer.answer){
|
||||||
|
c = Colors.red;
|
||||||
|
}
|
||||||
|
answerBoxes.add(
|
||||||
|
new SizedBox(
|
||||||
|
width: screenWidth / _startCount,
|
||||||
|
height: 100,
|
||||||
|
child: new DecoratedBox(
|
||||||
|
decoration: BoxDecoration(color: c)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return new Row(children: answerBoxes);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
MonthPracticeSetup setup = ModalRoute.of(context).settings.arguments;
|
MonthPracticeSetup setup = ModalRoute.of(context).settings.arguments;
|
||||||
if(_count == 0) {
|
_startCount = setup.count;
|
||||||
_count = setup.count;
|
|
||||||
}
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
drawer: AppDrawer(),
|
drawer: AppDrawer(),
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
@ -55,7 +76,7 @@ class _MonthPracticeState extends State<MonthPracticePage> {
|
||||||
"Correct: " + _correct.toString()
|
"Correct: " + _correct.toString()
|
||||||
),
|
),
|
||||||
new Text(
|
new Text(
|
||||||
_count.toString() + " left"
|
(_startCount - _count).toString() + " left"
|
||||||
),
|
),
|
||||||
new Text(
|
new Text(
|
||||||
"Incorrect: " + _incorrect.toString()
|
"Incorrect: " + _incorrect.toString()
|
||||||
|
@ -131,6 +152,10 @@ class _MonthPracticeState extends State<MonthPracticePage> {
|
||||||
child: new Text("0")
|
child: new Text("0")
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
),
|
||||||
|
new Align(
|
||||||
|
alignment: FractionalOffset.bottomCenter,
|
||||||
|
child: getAnswerRow()
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -138,18 +163,21 @@ class _MonthPracticeState extends State<MonthPracticePage> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkMonth(int value){
|
void checkMonth(int answer){
|
||||||
if(value == DayCalculator.getMonthValueByString(_month)){
|
int month = DayCalculator.getMonthValueByString(_month);
|
||||||
|
if(answer == month){
|
||||||
_correct += 1;
|
_correct += 1;
|
||||||
} else {
|
} else {
|
||||||
_incorrect += 1;
|
_incorrect += 1;
|
||||||
}
|
}
|
||||||
_count -= 1;
|
_count += 1;
|
||||||
|
answers.add(new MonthPracticeAnswer(month, answer));
|
||||||
|
if((_startCount - _count) == 0) {
|
||||||
|
Navigator.pop(context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
setState(() => {
|
setState(() => {
|
||||||
_month = _months[_random.nextInt(_months.length)]
|
_month = _months[_random.nextInt(_months.length)]
|
||||||
});
|
});
|
||||||
if(_count == 0) {
|
|
||||||
Navigator.pop(context);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue