can now hide correct month values when practicing

This commit is contained in:
BroodjeAap 2020-10-19 17:44:44 +02:00
parent 3e632627fe
commit 88eb570f63
3 changed files with 27 additions and 4 deletions

View file

@ -18,6 +18,7 @@ class _MonthPracticeState extends State<MonthPracticePage> {
int _count = 0; int _count = 0;
int _correct = 0; int _correct = 0;
int _incorrect = 0; int _incorrect = 0;
bool _showCorrect = true;
static final _random = new Random(); static final _random = new Random();
Month _month = Months.getFromInt(_random.nextInt(Months.length)); Month _month = Months.getFromInt(_random.nextInt(Months.length));
List<MonthPracticeAnswer> answers = new List<MonthPracticeAnswer>(); List<MonthPracticeAnswer> answers = new List<MonthPracticeAnswer>();
@ -55,11 +56,15 @@ class _MonthPracticeState extends State<MonthPracticePage> {
List<Widget> questions = List<Widget>(); List<Widget> questions = List<Widget>();
if(answers.length >= 2){ if(answers.length >= 2){
MonthPracticeAnswer answer = answers[answers.length - 2]; MonthPracticeAnswer answer = answers[answers.length - 2];
StringBuffer tmp = StringBuffer("${answer.month.string.capitalize()}");
if (_showCorrect){
tmp.write(": ${answer.month.value}");
}
questions.add( questions.add(
new Opacity( new Opacity(
opacity: 0.3, opacity: 0.3,
child: new Text( child: new Text(
"${answer.month.string.capitalize()}: ${answer.month.value}", tmp.toString(),
style: TextStyle( style: TextStyle(
fontSize: 10, fontSize: 10,
color: answer.answer == answer.month.value ? Colors.green : Colors.red color: answer.answer == answer.month.value ? Colors.green : Colors.red
@ -80,11 +85,15 @@ class _MonthPracticeState extends State<MonthPracticePage> {
} }
if(answers.length >= 1){ if(answers.length >= 1){
MonthPracticeAnswer answer = answers[answers.length - 1]; MonthPracticeAnswer answer = answers[answers.length - 1];
StringBuffer tmp = StringBuffer("${answer.month.string.capitalize()}");
if (_showCorrect){
tmp.write(": ${answer.month.value}");
}
questions.add( questions.add(
new Opacity( new Opacity(
opacity: 0.6, opacity: 0.6,
child: new Text( child: new Text(
"${answer.month.string.capitalize()}: ${answer.month.value}", tmp.toString(),
style: TextStyle( style: TextStyle(
fontSize: 15, fontSize: 15,
color: answer.answer == answer.month.value ? Colors.green : Colors.red color: answer.answer == answer.month.value ? Colors.green : Colors.red
@ -152,6 +161,7 @@ class _MonthPracticeState extends State<MonthPracticePage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
MonthPracticeSetup setup = ModalRoute.of(context).settings.arguments; MonthPracticeSetup setup = ModalRoute.of(context).settings.arguments;
_startCount = setup.count; _startCount = setup.count;
_showCorrect = setup.showCorrect;
return Scaffold( return Scaffold(
drawer: AppDrawer(), drawer: AppDrawer(),
appBar: AppBar( appBar: AppBar(

View file

@ -1,5 +1,6 @@
class MonthPracticeSetup { class MonthPracticeSetup {
final int count; final int count;
final bool showCorrect;
MonthPracticeSetup(this.count); MonthPracticeSetup(this.count, this.showCorrect);
} }

View file

@ -10,6 +10,7 @@ class MonthPracticeSetupPage extends StatefulWidget {
class _MonthPracticeSetupState extends State<MonthPracticeSetupPage> { class _MonthPracticeSetupState extends State<MonthPracticeSetupPage> {
int _count = 12; int _count = 12;
bool _showCorrect = true;
@override @override
Widget build(BuildContext context){ Widget build(BuildContext context){
return Scaffold( return Scaffold(
@ -33,12 +34,23 @@ class _MonthPracticeSetupState extends State<MonthPracticeSetupPage> {
onChanged: (newNumber) => onChanged: (newNumber) =>
setState(() => _count = newNumber), setState(() => _count = newNumber),
), ),
new SizedBox(height: 30),
new CheckboxListTile(
title: new Text("Show correct Answer"),
value: _showCorrect,
onChanged: (value) {
setState(() {
_showCorrect = !_showCorrect;
});
}
),
new SizedBox(height: 30),
new FlatButton( new FlatButton(
onPressed: () { onPressed: () {
Navigator.pushNamed( Navigator.pushNamed(
context, context,
'/practice/month/practice', '/practice/month/practice',
arguments: MonthPracticeSetup(_count) arguments: MonthPracticeSetup(_count, _showCorrect)
); );
}, },
child: new Text("Start!"), child: new Text("Start!"),