basic practice working
This commit is contained in:
parent
b78877721e
commit
65766771a6
3 changed files with 36 additions and 15 deletions
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:ohthatsa/pages/practice/month/MonthPracticeSetup.dart';
|
||||
import 'package:ohthatsa/util/DayCalculator.dart';
|
||||
import 'package:ohthatsa/AppDrawer.dart';
|
||||
import "dart:math";
|
||||
|
@ -9,9 +10,9 @@ class MonthPracticePage extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _MonthPracticeState extends State<MonthPracticePage> {
|
||||
int count = 0;
|
||||
int correct = 0;
|
||||
int incorrect = 0;
|
||||
int _count = 0;
|
||||
int _correct = 0;
|
||||
int _incorrect = 0;
|
||||
static final _random = new Random();
|
||||
static List<String> _months = [
|
||||
"January",
|
||||
|
@ -33,6 +34,10 @@ class _MonthPracticeState extends State<MonthPracticePage> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
MonthPracticeSetup setup = ModalRoute.of(context).settings.arguments;
|
||||
if(_count == 0) {
|
||||
_count = setup.count;
|
||||
}
|
||||
return Scaffold(
|
||||
drawer: AppDrawer(),
|
||||
appBar: AppBar(
|
||||
|
@ -45,13 +50,15 @@ class _MonthPracticeState extends State<MonthPracticePage> {
|
|||
padding: EdgeInsets.all(20),
|
||||
child: new Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
|
||||
children: <Widget>[
|
||||
new Text(
|
||||
"Correct: " + correct.toString()
|
||||
"Correct: " + _correct.toString()
|
||||
),
|
||||
new Text(
|
||||
"Incorrect: " + incorrect.toString()
|
||||
_count.toString() + " left"
|
||||
),
|
||||
new Text(
|
||||
"Incorrect: " + _incorrect.toString()
|
||||
)
|
||||
],
|
||||
)
|
||||
|
@ -133,12 +140,16 @@ class _MonthPracticeState extends State<MonthPracticePage> {
|
|||
|
||||
void checkMonth(int value){
|
||||
if(value == DayCalculator.getMonthValueByString(_month)){
|
||||
correct += 1;
|
||||
_correct += 1;
|
||||
} else {
|
||||
incorrect += 1;
|
||||
_incorrect += 1;
|
||||
}
|
||||
_count -= 1;
|
||||
setState(() => {
|
||||
_month = _months[_random.nextInt(_months.length)]
|
||||
});
|
||||
if(_count == 0) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
setState(() =>
|
||||
_month = _months[_random.nextInt(_months.length)]
|
||||
);
|
||||
}
|
||||
}
|
5
lib/pages/practice/month/MonthPracticeSetup.dart
Normal file
5
lib/pages/practice/month/MonthPracticeSetup.dart
Normal file
|
@ -0,0 +1,5 @@
|
|||
class MonthPracticeSetup {
|
||||
final int count;
|
||||
|
||||
MonthPracticeSetup(this.count);
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:numberpicker/numberpicker.dart';
|
||||
import 'package:ohthatsa/AppDrawer.dart';
|
||||
import 'package:ohthatsa/pages/practice/month/MonthPracticeSetup.dart';
|
||||
|
||||
class MonthPracticeSetupPage extends StatefulWidget {
|
||||
@override
|
||||
|
@ -8,7 +9,7 @@ class MonthPracticeSetupPage extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _MonthPracticeSetupState extends State<MonthPracticeSetupPage> {
|
||||
int _number = 5;
|
||||
int _count = 5;
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
return Scaffold(
|
||||
|
@ -21,15 +22,19 @@ class _MonthPracticeSetupState extends State<MonthPracticeSetupPage> {
|
|||
children: <Widget>[
|
||||
new Text("How many times would you like to practice?"),
|
||||
new NumberPicker.integer(
|
||||
initialValue: _number,
|
||||
initialValue: _count,
|
||||
minValue: 1,
|
||||
maxValue: 1000000,
|
||||
onChanged: (newNumber) =>
|
||||
setState(() => _number = newNumber),
|
||||
setState(() => _count = newNumber),
|
||||
),
|
||||
new FlatButton(
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, '/practice/month/practice');
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
'/practice/month/practice',
|
||||
arguments: MonthPracticeSetup(_count)
|
||||
);
|
||||
},
|
||||
child: new Text("Start!"),
|
||||
color: Colors.blue,
|
||||
|
|
Loading…
Add table
Reference in a new issue