randomize awnsers (seeded)

This commit is contained in:
jusax23 2023-06-01 20:23:13 +02:00
parent c38305d38c
commit 364ea48bcd
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41

View file

@ -1,3 +1,5 @@
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:ju_learn/main.dart';
@ -12,6 +14,7 @@ class QuizPage extends StatefulWidget {
}
class _QuizPageState extends State<QuizPage> {
int runSeed = Random().nextInt(0xffffff);
int run = 0;
Question _currentQuestion = Question("Dummy", ["Dummy aws"], 0, "dummy");
int askState = -1;
@ -108,28 +111,32 @@ class _QuizPageState extends State<QuizPage> {
),
),
const SizedBox(height: 20.0),
..._currentQuestion.answers.map(
(option) {
return Container(
margin: const EdgeInsets.symmetric(vertical: 8.0),
child: FilledButton(
onPressed: () => askState == -1
? _checkAnswer(
_currentQuestion.answers.indexOf(option),
)
: _nextQuestion(),
style: FilledButton.styleFrom(
padding: const EdgeInsets.all(16.0),
backgroundColor: askState == -1
? null
: (_currentQuestion.correct ==
_currentQuestion.answers.indexOf(option)
? Colors.green
: Colors.red),
),
child: Text(option)));
},
),
...() {
var l = _currentQuestion.answers.map(
(option) {
return Container(
margin: const EdgeInsets.symmetric(vertical: 8.0),
child: FilledButton(
onPressed: () => askState == -1
? _checkAnswer(
_currentQuestion.answers.indexOf(option),
)
: _nextQuestion(),
style: FilledButton.styleFrom(
padding: const EdgeInsets.all(16.0),
backgroundColor: askState == -1
? null
: (_currentQuestion.correct ==
_currentQuestion.answers.indexOf(option)
? Colors.green
: Colors.red),
),
child: Text(option)));
},
).toList();
l.shuffle(Random(run + runSeed));
return l;
}(),
if (askState != -1)
Text(
_currentQuestion.explanation,