Converting Map<String, Object> to List<Widget> in flutter, dart

Viewed 1800

I am using graphql-flutter in flutter I think my query result is LazaCaheMap which is Map. You can look here

Then I need to use that map for GridView. My code looks like this.

        List playlists = result.data['playlists'];

        return GridView.count(
          crossAxisCount: 2,
          mainAxisSpacing: 8,
          crossAxisSpacing: 8,
          padding: const EdgeInsets.all(8),
          childAspectRatio: 1,
          children: newPlaylist.map<Widget>((playlist) {
            return ChannelCard(
              playlistId: playlist['playlistId'],
              playlistTitle: playlist['playlistTitle'],
              thumbnailUrl: playlist['thumbnailUrl'],
              description: playlist['description'],
            );
          }),
        );

But as I expect, I got type 'MappedListIterable<Object, Widget>' is not a subtype of type 'List<Widget>' error. How can I convert this type?

1 Answers

There is a toList() method for converting an Iterable to a List.

somelist.map((f)=>{}).toList();
Related