material3, random

This commit is contained in:
jusax23 2023-06-01 16:38:20 +02:00
parent 1e94289d70
commit ea88aa0318
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41
2 changed files with 32 additions and 13 deletions

View file

@ -6,7 +6,11 @@ class QuizPage extends StatefulWidget {
QuizPage(this.v, {super.key}); QuizPage(this.v, {super.key});
@override @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<QuizPage> { class _QuizPageState extends State<QuizPage> {
@ -100,11 +104,19 @@ class _QuizPageState extends State<QuizPage> {
v.questions[_currentQuestionIndex].answers v.questions[_currentQuestionIndex].answers
.indexOf(option) .indexOf(option)
? Colors.green ? Colors.green
: Colors.red), // Change the button color here : Colors.red),
), foregroundColor: Colors.white),
)); ));
}, },
), ),
if (ask_state != -1)
Text(
v.questions[_currentQuestionIndex].explanation,
style: const TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
)
], ],
), ),
), ),

View file

@ -1,5 +1,6 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'dart:math';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
@ -16,9 +17,8 @@ class LearnApp extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
title: 'Learn App', title: 'Learn App',
theme: ThemeData( theme: ThemeData(useMaterial3: true, brightness: Brightness.light),
primarySwatch: Colors.blue, darkTheme: ThemeData(useMaterial3: true, brightness: Brightness.dark),
),
home: const MainPage(), home: const MainPage(),
); );
} }
@ -196,7 +196,14 @@ class Vault {
Vault(this.name, this.questions); Vault(this.name, this.questions);
Map<String, dynamic> toJson() { Map<String, dynamic> 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<String, dynamic> json) { factory Vault.fromJson(Map<String, dynamic> json) {