Step 78
This commit is contained in:
File diff suppressed because one or more lines are too long
Binary file not shown.
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
-1
@@ -1 +1 @@
|
||||
{"inputs":["C:\\Users\\birkeh\\Documents\\GitHub\\flutter\\Lerne Flutter\\The Complete Guide (2024 Edition)\\adv_basics\\.dart_tool\\package_config_subset"],"outputs":[]}
|
||||
{"inputs":["C:\\Users\\birkeh\\Documents\\GitHub\\flutter\\Lerne Flutter\\The Complete Guide (2024 Edition)\\adv_basics\\.dart_tool\\package_config_subset"],"outputs":["C:\\Users\\birkeh\\Documents\\GitHub\\flutter\\Lerne Flutter\\The Complete Guide (2024 Edition)\\adv_basics\\.dart_tool\\flutter_build\\dart_plugin_registrant.dart"]}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -4,7 +4,12 @@ import 'package:adv_basics/data/questions.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
class QuestionsScreen extends StatefulWidget {
|
||||
const QuestionsScreen(void Function() switchScreen, {super.key});
|
||||
const QuestionsScreen({
|
||||
super.key,
|
||||
required this.onSelectAnswer,
|
||||
});
|
||||
|
||||
final void Function(String answer) onSelectAnswer;
|
||||
|
||||
@override
|
||||
State<QuestionsScreen> createState() {
|
||||
@@ -15,7 +20,8 @@ class QuestionsScreen extends StatefulWidget {
|
||||
class _QuestionsScreenState extends State<QuestionsScreen> {
|
||||
var currentQuestionIndex = 0;
|
||||
|
||||
void answerQuestion() {
|
||||
void answerQuestion(String selectedAnswer) {
|
||||
widget.onSelectAnswer(selectedAnswer);
|
||||
setState(() {
|
||||
currentQuestionIndex++;
|
||||
});
|
||||
@@ -46,7 +52,9 @@ class _QuestionsScreenState extends State<QuestionsScreen> {
|
||||
...currentQuestion.getShuffeldAnswers().map((answer) {
|
||||
return AnswerButton(
|
||||
answerText: answer,
|
||||
onTap: answerQuestion,
|
||||
onTap: () {
|
||||
answerQuestion(answer);
|
||||
},
|
||||
);
|
||||
})
|
||||
],
|
||||
|
||||
+20
-1
@@ -1,5 +1,7 @@
|
||||
import 'package:adv_basics/questions_screen.dart';
|
||||
import 'package:adv_basics/start_screen.dart';
|
||||
import 'package:adv_basics/data/questions.dart';
|
||||
import 'package:adv_basics/results_screen.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Quiz extends StatefulWidget {
|
||||
@@ -12,6 +14,7 @@ class Quiz extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _QuizState extends State<Quiz> {
|
||||
List<String> selectedAnswers = [];
|
||||
var activeScreen = 'start-screen';
|
||||
|
||||
void switchScreen() {
|
||||
@@ -20,14 +23,30 @@ class _QuizState extends State<Quiz> {
|
||||
});
|
||||
}
|
||||
|
||||
void chooseAnswer(String answer) {
|
||||
selectedAnswers.add(answer);
|
||||
|
||||
if (selectedAnswers.length == questions.length) {
|
||||
setState(() {
|
||||
selectedAnswers = [];
|
||||
activeScreen = 'results-screen';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(context) {
|
||||
Widget screenWidget = StartScreen(switchScreen);
|
||||
|
||||
if (activeScreen == 'questions-screen') {
|
||||
screenWidget = QuestionsScreen(switchScreen);
|
||||
screenWidget = QuestionsScreen(
|
||||
onSelectAnswer: chooseAnswer,
|
||||
);
|
||||
}
|
||||
|
||||
if (activeScreen == 'results-screen') {
|
||||
screenWidget = const ResultsScreen();
|
||||
}
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Container(
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ResultsScreen extends StatelessWidget {
|
||||
const ResultsScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(40),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text('You answered X out of Y questions correctly!'),
|
||||
const SizedBox(
|
||||
height: 30,
|
||||
),
|
||||
const Text('List of answers and questions...'),
|
||||
const SizedBox(
|
||||
height: 30,
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: const Text('Restart Quiz!'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user