Unable to parse data from firebase in flutter

Viewed 84

Here is the model I am using for the data.

enter image description here

Here is the Future I am using to extract the data.

Future<List<Topic>> getTopics(String subjectid) async {

    var ref = db.collection('topics')
                    .where(
                      'subject',
                      isEqualTo: subjectid
                    );
    
    var snapshot = await ref.get();
    var data = snapshot.docs.map((s) => s.data());
    var topics = data.map((d) => Topic.fromJson(d));
    
    return topics.toList();

}

Here is how I have the data in firebase.

enter image description here

I am getting a error in the type cast:

type 'InternalLinkedHashMap<string, dynamic>' is not a subtype of type 'List<dynamic>?

When I try to print the topics.toList(), the print returns nothing.

I played around with my model, made sure all the columns are mapped correctly. My call for another collection works fine. But this one just won't work.

0 Answers
Related