main
Herwig Birke 2 years ago
parent ea751d1616
commit 57b71432f8

@ -245,10 +245,10 @@
"name": "adv_basics", "name": "adv_basics",
"rootUri": "../", "rootUri": "../",
"packageUri": "lib/", "packageUri": "lib/",
"languageVersion": "3.2" "languageVersion": "3.0"
} }
], ],
"generated": "2024-02-06T09:01:52.394894Z", "generated": "2024-02-08T07:21:52.882010Z",
"generator": "pub", "generator": "pub",
"generatorVersion": "3.2.6" "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/
file:///C:/Users/birkeh/AppData/Local/Pub/Cache/hosted/pub.dev/xdg_directories-1.0.4/lib/ file:///C:/Users/birkeh/AppData/Local/Pub/Cache/hosted/pub.dev/xdg_directories-1.0.4/lib/
adv_basics 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/
file:///C:/Users/birkeh/Documents/GitHub/flutter/Lerne%20Flutter/The%20Complete%20Guide%20(2024%20Edition)/adv_basics/lib/ file:///C:/Users/birkeh/Documents/GitHub/flutter/Lerne%20Flutter/The%20Complete%20Guide%20(2024%20Edition)/adv_basics/lib/
sky_engine 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'; import 'package:flutter/material.dart';
class AnswerButton extends StatelessWidget { class AnswerButton extends StatelessWidget {
const AnswerButton({ AnswerButton({
super.key, super.key,
required this.answerText, required this.answerText,
required this.onTap, required this.onTap,

@ -1,5 +1,4 @@
import 'package:adv_basics/quiz.dart'; import 'package:adv_basics/quiz.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
void main() { void main() {

@ -4,7 +4,7 @@ class QuizQuestion {
final String text; final String text;
final List<String> answers; final List<String> answers;
List<String> getShuffeldAnswers() { List<String> get shuffeldAnswers {
final shuffeldList = List.of(answers); final shuffeldList = List.of(answers);
shuffeldList.shuffle(); shuffeldList.shuffle();
return shuffeldList; return shuffeldList;

@ -49,7 +49,7 @@ class _QuestionsScreenState extends State<QuestionsScreen> {
textAlign: TextAlign.center, textAlign: TextAlign.center,
), ),
const SizedBox(height: 30), const SizedBox(height: 30),
...currentQuestion.getShuffeldAnswers().map((answer) { ...currentQuestion.shuffeldAnswers.map((answer) {
return AnswerButton( return AnswerButton(
answerText: answer, answerText: answer,
onTap: () { onTap: () {

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
class QuestionsSummary extends StatelessWidget { class QuestionsSummary extends StatelessWidget {
const QuestionsSummary(this.summaryData, {super.key}); const QuestionsSummary(this.summaryData, {super.key});
@ -12,19 +13,62 @@ class QuestionsSummary extends StatelessWidget {
child: SingleChildScrollView( child: SingleChildScrollView(
child: Column( child: Column(
children: summaryData.map( children: summaryData.map(
(data) { (data) {
return Row( return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ 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( Expanded(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text(data['question'] as String), Text(
SizedBox( data['question'] as String,
style: GoogleFonts.lato(
color: Colors.white,
fontSize: 14,
),
textAlign: TextAlign.left,
),
const SizedBox(
height: 5, height: 5,
), ),
Text(data['user_answer'] as String), Text(
Text(data['correct_answer'] as String), 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,
),
], ],
), ),
), ),

@ -18,6 +18,8 @@ class _QuizState extends State<Quiz> {
var activeScreen = 'start-screen'; var activeScreen = 'start-screen';
void switchScreen() { void switchScreen() {
selectedAnswers.clear();
setState(() { setState(() {
activeScreen = 'questions-screen'; activeScreen = 'questions-screen';
}); });
@ -44,8 +46,12 @@ class _QuizState extends State<Quiz> {
} }
if (activeScreen == 'results-screen') { if (activeScreen == 'results-screen') {
screenWidget = ResultsScreen(chosenAnswers: selectedAnswers); screenWidget = ResultsScreen(
chosenAnswers: selectedAnswers,
onRestartQuiz: switchScreen,
);
} }
return MaterialApp( return MaterialApp(
home: Scaffold( home: Scaffold(
body: Container( body: Container(
@ -59,9 +65,6 @@ class _QuizState extends State<Quiz> {
end: Alignment.bottomRight, end: Alignment.bottomRight,
), ),
), ),
// child: activeScreen == 'start-screen'
// ? StartScreen(switchScreen)
// : QuestionsScreen(switchScreen),
child: screenWidget, child: screenWidget,
), ),
), ),

@ -1,16 +1,19 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:adv_basics/data/questions.dart';
import 'package:adv_basics/questions_summary.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 { class ResultsScreen extends StatelessWidget {
const ResultsScreen({ const ResultsScreen({
super.key, super.key,
required this.chosenAnswers, required this.chosenAnswers,
required this.onRestartQuiz,
}); });
final List<String> chosenAnswers; 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 = []; final List<Map<String, Object>> summary = [];
for (var i = 0; i < chosenAnswers.length; i++) { for (var i = 0; i < chosenAnswers.length; i++) {
@ -29,11 +32,12 @@ class ResultsScreen extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final summaryData = getSummaryData(); final numTotalQuestions = summaryData.length;
final numTotalQuestions = questions.length; final numCorrectQuestions = summaryData
final numCorrectQuestions = summaryData.where((data) { .where(
return data['user_answer'] == data['correct_answer']; (data) => data['user_answer'] == data['correct_answer'],
}).length; )
.length;
return SizedBox( return SizedBox(
width: double.infinity, width: double.infinity,
@ -43,18 +47,31 @@ class ResultsScreen extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Text( 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( const SizedBox(
height: 30, height: 30,
), ),
QuestionsSummary(summaryData), QuestionsSummary(
summaryData,
),
const SizedBox( const SizedBox(
height: 30, height: 30,
), ),
TextButton( OutlinedButton.icon(
onPressed: () {}, onPressed: onRestartQuiz,
child: const Text('Restart Quiz!'), 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), icon: const Icon(Icons.arrow_right_alt),
label: const Text('Start Quiz'), label: const Text('Start Quiz'),
) ),
], ],
), ),
); );

@ -92,7 +92,7 @@ packages:
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
google_fonts: google_fonts:
dependency: "direct main" dependency: "direct dev"
description: description:
name: google_fonts name: google_fonts
sha256: f0b8d115a13ecf827013ec9fc883390ccc0e87a96ed5347a3114cac177ef18e8 sha256: f0b8d115a13ecf827013ec9fc883390ccc0e87a96ed5347a3114cac177ef18e8
@ -313,5 +313,5 @@ packages:
source: hosted source: hosted
version: "1.0.4" version: "1.0.4"
sdks: sdks:
dart: ">=3.2.5 <4.0.0" dart: ">=3.2.0 <4.0.0"
flutter: ">=3.10.0" flutter: ">=3.10.0"

@ -19,7 +19,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1 version: 1.0.0+1
environment: 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. # Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions # To automatically upgrade your package dependencies to the latest versions
@ -31,11 +31,9 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
# The following adds the Cupertino Icons font to your application. # 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 cupertino_icons: ^1.0.2
google_fonts: ^6.1.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
@ -47,6 +45,7 @@ dev_dependencies:
# package. See that file for information about deactivating specific lint # package. See that file for information about deactivating specific lint
# rules and activating additional ones. # rules and activating additional ones.
flutter_lints: ^3.0.1 flutter_lints: ^3.0.1
google_fonts: ^6.1.0
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec

Loading…
Cancel
Save