randomize awnsers (seeded)
This commit is contained in:
parent
c38305d38c
commit
364ea48bcd
1 changed files with 29 additions and 22 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:ju_learn/main.dart';
|
import 'package:ju_learn/main.dart';
|
||||||
|
|
||||||
|
@ -12,6 +14,7 @@ class QuizPage extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _QuizPageState extends State<QuizPage> {
|
class _QuizPageState extends State<QuizPage> {
|
||||||
|
int runSeed = Random().nextInt(0xffffff);
|
||||||
int run = 0;
|
int run = 0;
|
||||||
Question _currentQuestion = Question("Dummy", ["Dummy aws"], 0, "dummy");
|
Question _currentQuestion = Question("Dummy", ["Dummy aws"], 0, "dummy");
|
||||||
int askState = -1;
|
int askState = -1;
|
||||||
|
@ -108,28 +111,32 @@ class _QuizPageState extends State<QuizPage> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20.0),
|
const SizedBox(height: 20.0),
|
||||||
..._currentQuestion.answers.map(
|
...() {
|
||||||
(option) {
|
var l = _currentQuestion.answers.map(
|
||||||
return Container(
|
(option) {
|
||||||
margin: const EdgeInsets.symmetric(vertical: 8.0),
|
return Container(
|
||||||
child: FilledButton(
|
margin: const EdgeInsets.symmetric(vertical: 8.0),
|
||||||
onPressed: () => askState == -1
|
child: FilledButton(
|
||||||
? _checkAnswer(
|
onPressed: () => askState == -1
|
||||||
_currentQuestion.answers.indexOf(option),
|
? _checkAnswer(
|
||||||
)
|
_currentQuestion.answers.indexOf(option),
|
||||||
: _nextQuestion(),
|
)
|
||||||
style: FilledButton.styleFrom(
|
: _nextQuestion(),
|
||||||
padding: const EdgeInsets.all(16.0),
|
style: FilledButton.styleFrom(
|
||||||
backgroundColor: askState == -1
|
padding: const EdgeInsets.all(16.0),
|
||||||
? null
|
backgroundColor: askState == -1
|
||||||
: (_currentQuestion.correct ==
|
? null
|
||||||
_currentQuestion.answers.indexOf(option)
|
: (_currentQuestion.correct ==
|
||||||
? Colors.green
|
_currentQuestion.answers.indexOf(option)
|
||||||
: Colors.red),
|
? Colors.green
|
||||||
),
|
: Colors.red),
|
||||||
child: Text(option)));
|
),
|
||||||
},
|
child: Text(option)));
|
||||||
),
|
},
|
||||||
|
).toList();
|
||||||
|
l.shuffle(Random(run + runSeed));
|
||||||
|
return l;
|
||||||
|
}(),
|
||||||
if (askState != -1)
|
if (askState != -1)
|
||||||
Text(
|
Text(
|
||||||
_currentQuestion.explanation,
|
_currentQuestion.explanation,
|
||||||
|
|
Loading…
Reference in a new issue