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:flutter/material.dart';
|
||||||
|
import 'package:ohthatsa/pages/practice/month/MonthPracticeSetup.dart';
|
||||||
import 'package:ohthatsa/util/DayCalculator.dart';
|
import 'package:ohthatsa/util/DayCalculator.dart';
|
||||||
import 'package:ohthatsa/AppDrawer.dart';
|
import 'package:ohthatsa/AppDrawer.dart';
|
||||||
import "dart:math";
|
import "dart:math";
|
||||||
|
@ -9,9 +10,9 @@ class MonthPracticePage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MonthPracticeState extends State<MonthPracticePage> {
|
class _MonthPracticeState extends State<MonthPracticePage> {
|
||||||
int count = 0;
|
int _count = 0;
|
||||||
int correct = 0;
|
int _correct = 0;
|
||||||
int incorrect = 0;
|
int _incorrect = 0;
|
||||||
static final _random = new Random();
|
static final _random = new Random();
|
||||||
static List<String> _months = [
|
static List<String> _months = [
|
||||||
"January",
|
"January",
|
||||||
|
@ -33,6 +34,10 @@ class _MonthPracticeState extends State<MonthPracticePage> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
MonthPracticeSetup setup = ModalRoute.of(context).settings.arguments;
|
||||||
|
if(_count == 0) {
|
||||||
|
_count = setup.count;
|
||||||
|
}
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
drawer: AppDrawer(),
|
drawer: AppDrawer(),
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
@ -45,13 +50,15 @@ class _MonthPracticeState extends State<MonthPracticePage> {
|
||||||
padding: EdgeInsets.all(20),
|
padding: EdgeInsets.all(20),
|
||||||
child: new Row(
|
child: new Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Text(
|
new Text(
|
||||||
"Correct: " + correct.toString()
|
"Correct: " + _correct.toString()
|
||||||
),
|
),
|
||||||
new Text(
|
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){
|
void checkMonth(int value){
|
||||||
if(value == DayCalculator.getMonthValueByString(_month)){
|
if(value == DayCalculator.getMonthValueByString(_month)){
|
||||||
correct += 1;
|
_correct += 1;
|
||||||
} else {
|
} 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: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/month/MonthPracticeSetup.dart';
|
||||||
|
|
||||||
class MonthPracticeSetupPage extends StatefulWidget {
|
class MonthPracticeSetupPage extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
|
@ -8,7 +9,7 @@ class MonthPracticeSetupPage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MonthPracticeSetupState extends State<MonthPracticeSetupPage> {
|
class _MonthPracticeSetupState extends State<MonthPracticeSetupPage> {
|
||||||
int _number = 5;
|
int _count = 5;
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context){
|
Widget build(BuildContext context){
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
@ -21,15 +22,19 @@ class _MonthPracticeSetupState extends State<MonthPracticeSetupPage> {
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Text("How many times would you like to practice?"),
|
new Text("How many times would you like to practice?"),
|
||||||
new NumberPicker.integer(
|
new NumberPicker.integer(
|
||||||
initialValue: _number,
|
initialValue: _count,
|
||||||
minValue: 1,
|
minValue: 1,
|
||||||
maxValue: 1000000,
|
maxValue: 1000000,
|
||||||
onChanged: (newNumber) =>
|
onChanged: (newNumber) =>
|
||||||
setState(() => _number = newNumber),
|
setState(() => _count = newNumber),
|
||||||
),
|
),
|
||||||
new FlatButton(
|
new FlatButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pushNamed(context, '/practice/month/practice');
|
Navigator.pushNamed(
|
||||||
|
context,
|
||||||
|
'/practice/month/practice',
|
||||||
|
arguments: MonthPracticeSetup(_count)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
child: new Text("Start!"),
|
child: new Text("Start!"),
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
|
|
Loading…
Add table
Reference in a new issue