From ea88aa031883a8ce939e48c64085138efc7ba267 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Thu, 1 Jun 2023 16:38:20 +0200 Subject: [PATCH] material3, random --- lib/learn.dart | 30 +++++++++++++++++++++--------- lib/main.dart | 15 +++++++++++---- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/lib/learn.dart b/lib/learn.dart index 1df7b1f..ae1fa22 100644 --- a/lib/learn.dart +++ b/lib/learn.dart @@ -6,7 +6,11 @@ class QuizPage extends StatefulWidget { QuizPage(this.v, {super.key}); @override - _QuizPageState createState() => _QuizPageState(v); + // ignore: no_logic_in_create_state, library_private_types_in_public_api + _QuizPageState createState() { + v.randomize(); + return _QuizPageState(v); + } } class _QuizPageState extends State { @@ -94,17 +98,25 @@ class _QuizPageState extends State { : _nextQuestion(), child: Text(option), style: ElevatedButton.styleFrom( - backgroundColor: ask_state == -1 - ? Colors.blue - : (v.questions[_currentQuestionIndex].correct == - v.questions[_currentQuestionIndex].answers - .indexOf(option) - ? Colors.green - : Colors.red), // Change the button color here - ), + backgroundColor: ask_state == -1 + ? Colors.blue + : (v.questions[_currentQuestionIndex].correct == + v.questions[_currentQuestionIndex].answers + .indexOf(option) + ? Colors.green + : Colors.red), + foregroundColor: Colors.white), )); }, ), + if (ask_state != -1) + Text( + v.questions[_currentQuestionIndex].explanation, + style: const TextStyle( + fontSize: 15.0, + fontWeight: FontWeight.bold, + ), + ) ], ), ), diff --git a/lib/main.dart b/lib/main.dart index 7912e1e..f318078 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'dart:io'; +import 'dart:math'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/foundation.dart'; @@ -16,9 +17,8 @@ class LearnApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Learn App', - theme: ThemeData( - primarySwatch: Colors.blue, - ), + theme: ThemeData(useMaterial3: true, brightness: Brightness.light), + darkTheme: ThemeData(useMaterial3: true, brightness: Brightness.dark), home: const MainPage(), ); } @@ -196,7 +196,14 @@ class Vault { Vault(this.name, this.questions); Map toJson() { - return {"name": name, "questions": questions.map((e) => e.toJson()).toList()}; + return { + "name": name, + "questions": questions.map((e) => e.toJson()).toList() + }; + } + + void randomize() { + questions.shuffle(Random()); } factory Vault.fromJson(Map json) {