diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index 29cd23f..c34bf7c 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -245,10 +245,10 @@ "name": "adv_basics", "rootUri": "../", "packageUri": "lib/", - "languageVersion": "3.2" + "languageVersion": "3.0" } ], - "generated": "2024-02-06T09:01:52.394894Z", + "generated": "2024-02-08T07:21:52.882010Z", "generator": "pub", "generatorVersion": "3.2.6" } diff --git a/.dart_tool/package_config_subset b/.dart_tool/package_config_subset index b407495..fead87e 100644 --- a/.dart_tool/package_config_subset +++ b/.dart_tool/package_config_subset @@ -147,7 +147,7 @@ xdg_directories file:///C:/Users/birkeh/AppData/Local/Pub/Cache/hosted/pub.dev/xdg_directories-1.0.4/ file:///C:/Users/birkeh/AppData/Local/Pub/Cache/hosted/pub.dev/xdg_directories-1.0.4/lib/ adv_basics -3.2 +3.0 file:///C:/Users/birkeh/Documents/GitHub/flutter/Lerne%20Flutter/The%20Complete%20Guide%20(2024%20Edition)/adv_basics/ file:///C:/Users/birkeh/Documents/GitHub/flutter/Lerne%20Flutter/The%20Complete%20Guide%20(2024%20Edition)/adv_basics/lib/ sky_engine diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 763a256..da4bd26 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\birkeh\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.3.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"C:\\\\Users\\\\birkeh\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.2.2\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\birkeh\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.3.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\birkeh\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.2.1\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\birkeh\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.2.1\\\\","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2024-02-06 15:11:32.548844","version":"3.16.9"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\birkeh\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.3.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"C:\\\\Users\\\\birkeh\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.2.2\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\birkeh\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.3.2\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\birkeh\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.2.1\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\birkeh\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.2.1\\\\","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2024-02-08 08:21:53.083210","version":"3.16.9"} \ No newline at end of file diff --git a/lib/answer_button.dart b/lib/answer_button.dart index 6b1fc0c..b94f932 100644 --- a/lib/answer_button.dart +++ b/lib/answer_button.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; class AnswerButton extends StatelessWidget { - const AnswerButton({ + AnswerButton({ super.key, required this.answerText, required this.onTap, diff --git a/lib/main.dart b/lib/main.dart index c01da00..70d8038 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,4 @@ import 'package:adv_basics/quiz.dart'; - import 'package:flutter/material.dart'; void main() { diff --git a/lib/models/quiz_question.dart b/lib/models/quiz_question.dart index 4d05086..7e9aee3 100644 --- a/lib/models/quiz_question.dart +++ b/lib/models/quiz_question.dart @@ -4,7 +4,7 @@ class QuizQuestion { final String text; final List answers; - List getShuffeldAnswers() { + List get shuffeldAnswers { final shuffeldList = List.of(answers); shuffeldList.shuffle(); return shuffeldList; diff --git a/lib/questions_screen.dart b/lib/questions_screen.dart index 6e16a3e..327ee2c 100644 --- a/lib/questions_screen.dart +++ b/lib/questions_screen.dart @@ -49,7 +49,7 @@ class _QuestionsScreenState extends State { textAlign: TextAlign.center, ), const SizedBox(height: 30), - ...currentQuestion.getShuffeldAnswers().map((answer) { + ...currentQuestion.shuffeldAnswers.map((answer) { return AnswerButton( answerText: answer, onTap: () { diff --git a/lib/questions_summary.dart b/lib/questions_summary.dart index b005fd8..a25b1b6 100644 --- a/lib/questions_summary.dart +++ b/lib/questions_summary.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; class QuestionsSummary extends StatelessWidget { const QuestionsSummary(this.summaryData, {super.key}); @@ -12,19 +13,62 @@ class QuestionsSummary extends StatelessWidget { child: SingleChildScrollView( child: Column( children: summaryData.map( - (data) { + (data) { return Row( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(((data['question_index'] as int) + 1).toString()), + CircleAvatar( + radius: 15, + backgroundColor: + (data['correct_answer'] == data['user_answer']) + ? Colors.green + : Colors.red, + child: Center( + child: Text( + ((data['question_index'] as int) + 1).toString(), + style: const TextStyle( + color: Colors.white, + ), + ), + ), + ), + SizedBox( + width: 20, + ), Expanded( child: Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(data['question'] as String), - SizedBox( + Text( + data['question'] as String, + style: GoogleFonts.lato( + color: Colors.white, + fontSize: 14, + ), + textAlign: TextAlign.left, + ), + const SizedBox( height: 5, ), - Text(data['user_answer'] as String), - Text(data['correct_answer'] as String), + Text( + data['user_answer'] as String, + style: GoogleFonts.lato( + color: Color.fromARGB(255, 201, 153, 251), + fontSize: 14, + ), + textAlign: TextAlign.left, + ), + Text( + data['correct_answer'] as String, + style: GoogleFonts.lato( + color: + (data['correct_answer'] == data['user_answer']) + ? Colors.green + : Colors.red, + fontSize: 14, + ), + textAlign: TextAlign.left, + ), ], ), ), diff --git a/lib/quiz.dart b/lib/quiz.dart index a0e1681..826306a 100644 --- a/lib/quiz.dart +++ b/lib/quiz.dart @@ -18,6 +18,8 @@ class _QuizState extends State { var activeScreen = 'start-screen'; void switchScreen() { + selectedAnswers.clear(); + setState(() { activeScreen = 'questions-screen'; }); @@ -44,8 +46,12 @@ class _QuizState extends State { } if (activeScreen == 'results-screen') { - screenWidget = ResultsScreen(chosenAnswers: selectedAnswers); + screenWidget = ResultsScreen( + chosenAnswers: selectedAnswers, + onRestartQuiz: switchScreen, + ); } + return MaterialApp( home: Scaffold( body: Container( @@ -59,9 +65,6 @@ class _QuizState extends State { end: Alignment.bottomRight, ), ), -// child: activeScreen == 'start-screen' -// ? StartScreen(switchScreen) -// : QuestionsScreen(switchScreen), child: screenWidget, ), ), diff --git a/lib/results_screen.dart b/lib/results_screen.dart index 1b678b3..0b9f1d3 100644 --- a/lib/results_screen.dart +++ b/lib/results_screen.dart @@ -1,16 +1,19 @@ import 'package:flutter/material.dart'; -import 'package:adv_basics/data/questions.dart'; import 'package:adv_basics/questions_summary.dart'; +import 'package:adv_basics/data/questions.dart'; +import 'package:google_fonts/google_fonts.dart'; class ResultsScreen extends StatelessWidget { const ResultsScreen({ super.key, required this.chosenAnswers, + required this.onRestartQuiz, }); final List chosenAnswers; + final void Function() onRestartQuiz; - List> getSummaryData() { + List> get summaryData { final List> summary = []; for (var i = 0; i < chosenAnswers.length; i++) { @@ -29,11 +32,12 @@ class ResultsScreen extends StatelessWidget { @override Widget build(BuildContext context) { - final summaryData = getSummaryData(); - final numTotalQuestions = questions.length; - final numCorrectQuestions = summaryData.where((data) { - return data['user_answer'] == data['correct_answer']; - }).length; + final numTotalQuestions = summaryData.length; + final numCorrectQuestions = summaryData + .where( + (data) => data['user_answer'] == data['correct_answer'], + ) + .length; return SizedBox( width: double.infinity, @@ -43,18 +47,31 @@ class ResultsScreen extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, children: [ Text( - 'You answered $numCorrectQuestions out of $numTotalQuestions questions correctly!'), + 'You answered $numCorrectQuestions out of $numTotalQuestions questions correctly!', + style: GoogleFonts.lato( + color: const Color.fromARGB(255, 201, 153, 251), + fontSize: 24, + fontWeight: FontWeight.bold, + ), + textAlign: TextAlign.center, + ), const SizedBox( height: 30, ), - QuestionsSummary(summaryData), + QuestionsSummary( + summaryData, + ), const SizedBox( height: 30, ), - TextButton( - onPressed: () {}, - child: const Text('Restart Quiz!'), - ), + OutlinedButton.icon( + onPressed: onRestartQuiz, + style: OutlinedButton.styleFrom( + foregroundColor: Colors.white, + ), + icon: const Icon(Icons.update), + label: const Text('Restart Quiz'), + ) ], ), ), diff --git a/lib/start_screen.dart b/lib/start_screen.dart index e4236d5..215ef00 100644 --- a/lib/start_screen.dart +++ b/lib/start_screen.dart @@ -35,7 +35,7 @@ class StartScreen extends StatelessWidget { ), icon: const Icon(Icons.arrow_right_alt), label: const Text('Start Quiz'), - ) + ), ], ), ); diff --git a/pubspec.lock b/pubspec.lock index e07849c..d0c1343 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -92,7 +92,7 @@ packages: source: sdk version: "0.0.0" google_fonts: - dependency: "direct main" + dependency: "direct dev" description: name: google_fonts sha256: f0b8d115a13ecf827013ec9fc883390ccc0e87a96ed5347a3114cac177ef18e8 @@ -313,5 +313,5 @@ packages: source: hosted version: "1.0.4" sdks: - dart: ">=3.2.5 <4.0.0" + dart: ">=3.2.0 <4.0.0" flutter: ">=3.10.0" diff --git a/pubspec.yaml b/pubspec.yaml index 6b980b8..25b82b5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,7 +19,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: '>=3.2.5 <4.0.0' + sdk: ">=3.0.0 <4.0.0" # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions @@ -31,11 +31,9 @@ dependencies: flutter: sdk: flutter - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. + # Use with the CupertinoIcons class for iOS styles icons. cupertino_icons: ^1.0.2 - google_fonts: ^6.1.0 dev_dependencies: flutter_test: @@ -47,6 +45,7 @@ dev_dependencies: # package. See that file for information about deactivating specific lint # rules and activating additional ones. flutter_lints: ^3.0.1 + google_fonts: ^6.1.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec