Added simple practice page for month values
This commit is contained in:
parent
4aaddecbd0
commit
11a6d765c1
4 changed files with 201 additions and 0 deletions
|
@ -25,6 +25,13 @@ class AppDrawer extends StatelessWidget {
|
|||
Navigator.pushNamed(context, "/years");
|
||||
}
|
||||
),
|
||||
ListTile(
|
||||
title: Text("Practice Months"),
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
Navigator.pushNamed(context, "/practice/month/setup");
|
||||
}
|
||||
),
|
||||
],
|
||||
)
|
||||
);
|
||||
|
|
145
lib/MonthPracticePage.dart
Normal file
145
lib/MonthPracticePage.dart
Normal file
|
@ -0,0 +1,145 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:numberpicker/numberpicker.dart';
|
||||
import 'package:ohthatsa/DayCalculator.dart';
|
||||
import 'AppDrawer.dart';
|
||||
import "dart:math";
|
||||
|
||||
class MonthPracticePage extends StatefulWidget {
|
||||
@override
|
||||
_MonthPracticeState createState() => _MonthPracticeState();
|
||||
}
|
||||
|
||||
class _MonthPracticeState extends State<MonthPracticePage> {
|
||||
int count = 0;
|
||||
int correct = 0;
|
||||
int incorrect = 0;
|
||||
static final _random = new Random();
|
||||
static List<String> _months = [
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December"
|
||||
];
|
||||
String _month = _months[_random.nextInt(_months.length)];
|
||||
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
drawer: AppDrawer(),
|
||||
appBar: AppBar(
|
||||
title: Text("Practicing months"),
|
||||
),
|
||||
body: Center(
|
||||
child: new Column(
|
||||
children: <Widget>[
|
||||
new Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: new Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
|
||||
children: <Widget>[
|
||||
new Text(
|
||||
"Correct: " + correct.toString()
|
||||
),
|
||||
new Text(
|
||||
"Incorrect: " + incorrect.toString()
|
||||
)
|
||||
],
|
||||
)
|
||||
),
|
||||
new Text(
|
||||
_month
|
||||
),
|
||||
new GridView.count(
|
||||
primary: false,
|
||||
crossAxisCount: 3,
|
||||
padding: EdgeInsets.all(50),
|
||||
mainAxisSpacing: 10,
|
||||
crossAxisSpacing: 10,
|
||||
shrinkWrap: true,
|
||||
children: <Widget>[
|
||||
new FlatButton(
|
||||
onPressed: () {
|
||||
checkMonth(1);
|
||||
},
|
||||
color: Colors.blue,
|
||||
textColor: Colors.white,
|
||||
child: new Text("1")
|
||||
),
|
||||
new FlatButton(
|
||||
onPressed: () {
|
||||
checkMonth(2);
|
||||
},
|
||||
color: Colors.blue,
|
||||
textColor: Colors.white,
|
||||
child: new Text("2")
|
||||
),
|
||||
new FlatButton(
|
||||
onPressed: () {
|
||||
checkMonth(3);
|
||||
},
|
||||
color: Colors.blue,
|
||||
textColor: Colors.white,
|
||||
child: new Text("3")
|
||||
),
|
||||
new FlatButton(
|
||||
onPressed: () {
|
||||
checkMonth(4);
|
||||
},
|
||||
color: Colors.blue,
|
||||
textColor: Colors.white,
|
||||
child: new Text("4")
|
||||
),
|
||||
new FlatButton(
|
||||
onPressed: () {
|
||||
checkMonth(5);
|
||||
},
|
||||
color: Colors.blue,
|
||||
textColor: Colors.white,
|
||||
child: new Text("5")
|
||||
),
|
||||
new FlatButton(
|
||||
onPressed: () {
|
||||
checkMonth(6);
|
||||
},
|
||||
color: Colors.blue,
|
||||
textColor: Colors.white,
|
||||
child: new Text("6")
|
||||
),
|
||||
new FlatButton(
|
||||
onPressed: () {
|
||||
checkMonth(0);
|
||||
},
|
||||
color: Colors.blue,
|
||||
textColor: Colors.white,
|
||||
child: new Text("0")
|
||||
)
|
||||
]
|
||||
)
|
||||
],
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void checkMonth(int value){
|
||||
if(value == DayCalculator.getMonthValueByString(_month)){
|
||||
correct += 1;
|
||||
} else {
|
||||
incorrect += 1;
|
||||
}
|
||||
setState(() =>
|
||||
_month = _months[_random.nextInt(_months.length)]
|
||||
);
|
||||
}
|
||||
}
|
45
lib/MonthPracticeSetupPage.dart
Normal file
45
lib/MonthPracticeSetupPage.dart
Normal file
|
@ -0,0 +1,45 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:numberpicker/numberpicker.dart';
|
||||
import 'AppDrawer.dart';
|
||||
|
||||
class MonthPracticeSetupPage extends StatefulWidget {
|
||||
@override
|
||||
_MonthPracticeSetupState createState() => _MonthPracticeSetupState();
|
||||
}
|
||||
|
||||
class _MonthPracticeSetupState extends State<MonthPracticeSetupPage> {
|
||||
int _number = 5;
|
||||
@override
|
||||
Widget build(BuildContext context){
|
||||
return Scaffold(
|
||||
drawer: AppDrawer(),
|
||||
appBar: AppBar(
|
||||
title: Text("Practice Months"),
|
||||
),
|
||||
body: Center(
|
||||
child: new Column(
|
||||
children: <Widget>[
|
||||
new Text("How many times would you like to practice?"),
|
||||
new NumberPicker.integer(
|
||||
initialValue: _number,
|
||||
minValue: 1,
|
||||
maxValue: 1000000,
|
||||
onChanged: (newNumber) =>
|
||||
setState(() => _number = newNumber),
|
||||
),
|
||||
new FlatButton(
|
||||
onPressed: () {
|
||||
Navigator.pushNamed(context, '/practice/month/practice');
|
||||
},
|
||||
child: new Text("Start!"),
|
||||
color: Colors.blue,
|
||||
textColor: Colors.white,
|
||||
padding: EdgeInsets.all(8.0)
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:ohthatsa/MonthPracticeSetupPage.dart';
|
||||
import 'package:ohthatsa/YearsPage.dart';
|
||||
|
||||
import 'MonthPracticePage.dart';
|
||||
import 'MonthValuesPage.dart';
|
||||
|
||||
void main() {
|
||||
|
@ -17,6 +19,8 @@ class OhThatsA extends StatelessWidget {
|
|||
routes: {
|
||||
'/monthValues': (context) => MonthValuesPage(),
|
||||
'/years': (context) => YearsPage(),
|
||||
'/practice/month/setup': (context) => MonthPracticeSetupPage(),
|
||||
'/practice/month/practice': (context) => MonthPracticePage(),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue