Reputation: 41
I have the following data in Firebase:
In Flutter, I have the following two objects:
I'm trying to convert the nested map of sets in Firebase to the List in Flutter but am having issues. What is the best way to convert a Map object with Map fields into a List in Flutter?
I've tried mapping the sets via this method and two different techniques:
I know I'm having an issue handling the map object and I've received different errors depending on my approach but usually it is similar to one of the following:
Error 1: "type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'List'"
Error 2: "type '(dynamic) => ExerciseSet' is not a subtype of type '(dynamic, dynamic) => MapEntry<dynamic, dynamic>' of 'transform'"
Thank you for any help!
Upvotes: 1
Views: 1370
Reputation: 41
I can't believe after spending so many hours and finally deciding to post... I fixed it right after. Here's my working code:
Thank you for the quick response @Sanjay! I'll give yours a try to see if that works as well.
Upvotes: 0
Reputation: 4035
If you have List of objects inside one object then you need to parse the list separately as the following
sets = (json['sets'] as List)
.map((data) => ExerciseSet.fromJson(data))
.toList();
Here json
is decoded JSON.
Upvotes: 1