finished
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"}
|
||||
{"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"}
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AnswerButton extends StatelessWidget {
|
||||
const AnswerButton({
|
||||
AnswerButton({
|
||||
super.key,
|
||||
required this.answerText,
|
||||
required this.onTap,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:adv_basics/quiz.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() {
|
||||
|
||||
@@ -4,7 +4,7 @@ class QuizQuestion {
|
||||
final String text;
|
||||
final List<String> answers;
|
||||
|
||||
List<String> getShuffeldAnswers() {
|
||||
List<String> get shuffeldAnswers {
|
||||
final shuffeldList = List.of(answers);
|
||||
shuffeldList.shuffle();
|
||||
return shuffeldList;
|
||||
|
||||
@@ -49,7 +49,7 @@ class _QuestionsScreenState extends State<QuestionsScreen> {
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
...currentQuestion.getShuffeldAnswers().map((answer) {
|
||||
...currentQuestion.shuffeldAnswers.map((answer) {
|
||||
return AnswerButton(
|
||||
answerText: answer,
|
||||
onTap: () {
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
+7
-4
@@ -18,6 +18,8 @@ class _QuizState extends State<Quiz> {
|
||||
var activeScreen = 'start-screen';
|
||||
|
||||
void switchScreen() {
|
||||
selectedAnswers.clear();
|
||||
|
||||
setState(() {
|
||||
activeScreen = 'questions-screen';
|
||||
});
|
||||
@@ -44,8 +46,12 @@ class _QuizState extends State<Quiz> {
|
||||
}
|
||||
|
||||
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<Quiz> {
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
),
|
||||
// child: activeScreen == 'start-screen'
|
||||
// ? StartScreen(switchScreen)
|
||||
// : QuestionsScreen(switchScreen),
|
||||
child: screenWidget,
|
||||
),
|
||||
),
|
||||
|
||||
+30
-13
@@ -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<String> chosenAnswers;
|
||||
final void Function() onRestartQuiz;
|
||||
|
||||
List<Map<String, Object>> getSummaryData() {
|
||||
List<Map<String, Object>> get summaryData {
|
||||
final List<Map<String, Object>> 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'),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -35,7 +35,7 @@ class StartScreen extends StatelessWidget {
|
||||
),
|
||||
icon: const Icon(Icons.arrow_right_alt),
|
||||
label: const Text('Start Quiz'),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
+2
-2
@@ -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"
|
||||
|
||||
+3
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user