Home > Software design >  The following _TypeError was thrown building: type 'MappedListIterable<AkcijeDokument, Widge
The following _TypeError was thrown building: type 'MappedListIterable<AkcijeDokument, Widge

Time:09-16

I am fetching list of documents from api and every document has property actions(List of actions). Documents are displayed in a List and i want to display actions in ActionPane/SlidableAction an I get an error: "Another exception was thrown: type 'MappedListIterable<AkcijeDokument, dynamic>' is not a subtype of type 'Widget'". And error "The following _TypeError was thrown building: type 'MappedListIterable<AkcijeDokument, dynamic>' is not a subtype of type 'Widget'"...

When I print actions like this params[index].akcije.map((ak) => print(ak.nazivAkcije)) I get response: "I/flutter (25152): Potvrdi I/flutter (25152): Odbij", "Potvrdi" and "Odbij" are the actions that i need to fetch and display in List for each document.

And here is the code where I'm trying to display the actions

params[index].akcije.map<Widget>(
      (ak) => SlidableAction(
        onPressed: (context) {},
        icon: Icons.bookmark,
        backgroundColor: Colors.red,
        label: ak.nazivAkcije,
       ),
     ),,```

CodePudding user response:

First error is because you use map<Widget>() when the type you have in. a map is {AkcjeDokument, dynamic}

If what you want is to just print them use .map()

CodePudding user response:

You can try:

List<Widget> ak_list;
  for (var ak in params[index].akcije) {
    ak_list.add(SlidableAction(
        onPressed: (context) {},
        icon: Icons.bookmark,
        backgroundColor: Colors.red,
        label: ak.nazivAkcije,
    ));
 }

and use

//example after init
Column(children: ak_list);
  • Related