From 88e851180c69f47beb6150bd620241553e5bdb99 Mon Sep 17 00:00:00 2001 From: Nii Abe Abbey Date: Thu, 25 Nov 2021 13:21:35 +0000 Subject: [PATCH] Add score count Added a score count that shows the users score on complete. --- lib/main.dart | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 4f6bbfe..f03eba8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -31,6 +31,8 @@ class QuizPage extends StatefulWidget { class _QuizPageState extends State { List scoreKeeper = []; + // check players score + int score=0; void checkAnswer(bool userPickedAnswer) { bool correctAnswer = quizBrain.getCorrectAnswer(); @@ -48,8 +50,11 @@ class _QuizPageState extends State { Alert( context: context, title: 'Finished!', - desc: 'You\'ve reached the end of the quiz.', + desc: 'You\'ve reached the end of the quiz. Score: $score / 13', ).show(); + + // reset score + score=0; //TODO Step 4 Part C - reset the questionNumber, quizBrain.reset(); @@ -61,6 +66,10 @@ class _QuizPageState extends State { //TODO: Step 6 - If we've not reached the end, ELSE do the answer checking steps below 👇 else { if (userPickedAnswer == correctAnswer) { + if(score< 0){ + score = 0; + } + score++; scoreKeeper.add(Icon( Icons.check, color: Colors.green, @@ -137,9 +146,13 @@ class _QuizPageState extends State { ), ), ), - Row( - children: scoreKeeper, - ) + Flexible( + child: Center( + child: Row( + children: scoreKeeper, + ), + ), + ), ], ); }