Home > Blockchain >  How to fetch a Map<String, List<bool>> from firestore?
How to fetch a Map<String, List<bool>> from firestore?

Time:07-13

I am trying to fetch data from firestore, but I struggle with this part :

enter image description here

Flutter throw this error : E/flutter (31422): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<bool>' in type cast

To fetch firestore data, I have a fromMap function used to transform the document into an object :

Round.fromMap(Map snapshot)
  : round = snapshot['round'],
    isFinished = snapshot['isFinished'] ?? false,
    questions = List<Question>.from(
        snapshot['questions']?.map((x) => Question.fromMap(x))),
    playersAnswers =
        Map<String, List<bool>>.from(snapshot['playersAnswers']);

Do you have any tips to make this work ?

CodePudding user response:

The only thing I can think of is playersAnswers = Map.from(snapshot['playersAnswers'] as Map<String, List<bool>>) because I think Map.from is considering snapshot['playersAnswers'] as Map<String, dynamic> instead of Map<String, List<bool>> but I agree that this is a "dirty" solution.

  • Related