initializeData method
- dynamic data
Initialize the data from the JSON file in the provider
We load the choices and assetPath from JSON file to shuffle it.
Then we load choices and assetPath to the provider after the
shuffle these two lists in the same order.
Then, we load the lives and question from the JSON file.
Finally, we set the isInitialized to true, to prevent multiple data initialization
Implementation
void initializeData(dynamic data) async {
questions = (data["questionAnswer"] as List)
.map((dynamic e) => e as Map<String, dynamic>)
.toList();
_multipleChoices = (data["choices"] as List<dynamic>)
.map((dynamic e) => (e as List<dynamic>).cast<String>())
.toList();
questions.map((elem) => answersString.add(elem["answer"].join())).toList();
final List<int> indices = List.generate(questions.length, (i) => i);
indices.shuffle();
_answerQueue.addAll(indices);
lives = data["lives"];
question = data["question"];
selectedAnswer = List<String>.filled(_multipleChoices.length, "");
answer = _answerQueue.first;
isInitialized = true;
}