0
votes

I have the following data in Firebase:

enter image description here

In Flutter, I have the following two objects:

enter image description here

enter image description here

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: enter image description here

enter image description here

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!

2
On Stack Overflow,please do not show pictures of code and text. Copy the code into the question and format it so that it's easy to read, copy, and search. - Doug Stevenson
That makes total sense... Will do in the future! - Matthew Ramsey
I suggest doing it today in order to better serve the folks who might help you. You can edit the question using the edit link at the bottom. - Doug Stevenson

2 Answers

1
votes

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.

0
votes

I can't believe after spending so many hours and finally deciding to post... I fixed it right after. Here's my working code:

enter image description here

Thank you for the quick response @Sanjay! I'll give yours a try to see if that works as well.