From 0bb44589e18a3a918868b5eba4b3967cc1635285 Mon Sep 17 00:00:00 2001 From: Darren Gegantino Date: Fri, 8 May 2020 19:36:46 +0800 Subject: [PATCH] Show last answer result to user when dialog appears - This moves Step 4 C and D inside Alert widget's DialogButton's onPressed property so that scoreKeeper and questionNumber will only reset state when user confirms in the dialog box. - This also styles the Alert widget to have an overlayColor of a more lighter color so when it appears, the icons are still visible. --- lib/main.dart | 55 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 4f6bbfe..af367a1 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -46,33 +46,42 @@ class _QuizPageState extends State { //Modified for our purposes: Alert( - context: context, - title: 'Finished!', - desc: 'You\'ve reached the end of the quiz.', - ).show(); - - //TODO Step 4 Part C - reset the questionNumber, - quizBrain.reset(); - - //TODO Step 4 Part D - empty out the scoreKeeper. - scoreKeeper = []; + context: context, + title: 'Finished!', + desc: 'You\'ve reached the end of the quiz.', + style: AlertStyle(overlayColor: Colors.black54), + buttons: [ + DialogButton( + child: Text( + 'Restart', + style: TextStyle(color: Colors.white), + ), + onPressed: () { + setState(() { + //TODO Step 4 Part C - reset the questionNumber, + quizBrain.reset(); + //TODO Step 4 Part D - empty out the scoreKeeper. + scoreKeeper = []; + }); + Navigator.pop(context); + }, + ) + ]).show(); } //TODO: Step 6 - If we've not reached the end, ELSE do the answer checking steps below 👇 - else { - if (userPickedAnswer == correctAnswer) { - scoreKeeper.add(Icon( - Icons.check, - color: Colors.green, - )); - } else { - scoreKeeper.add(Icon( - Icons.close, - color: Colors.red, - )); - } - quizBrain.nextQuestion(); + if (userPickedAnswer == correctAnswer) { + scoreKeeper.add(Icon( + Icons.check, + color: Colors.green, + )); + } else { + scoreKeeper.add(Icon( + Icons.close, + color: Colors.red, + )); } + quizBrain.nextQuestion(); }); }