From 364ea48bcd7e0ce93d535686b03f981e6ffbf243 Mon Sep 17 00:00:00 2001 From: jusax23 Date: Thu, 1 Jun 2023 20:23:13 +0200 Subject: [PATCH] randomize awnsers (seeded) --- lib/learn.dart | 51 ++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/lib/learn.dart b/lib/learn.dart index b1d6af0..b03de55 100644 --- a/lib/learn.dart +++ b/lib/learn.dart @@ -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 { + 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 { ), ), 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,