initializeData method

void initializeData(
  1. 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) {
  final List<String> choicesData = data["choices"].cast<String>();
  final List<int> indices = List.generate(choicesData.length, (i) => i);

  indices.shuffle();
  _answerQueue.addAll(indices);

  questions = data["questionAssetPath"].cast<String>();
  choices = indices.map((i) => choicesData[i]).toSet().toList();
  questions = indices.map((i) => questions[i]).toSet().toList();

  lives = data["lives"];
  question = data["question"];
  answer = _answerQueue.first;
  isInitialized = true;
}