[Solved] List is not a subtype of type List Error in Flutter
In this post, we are going to show you how to solve "List<dynamic> is not a subtype of type List<Widget>" Error in Flutter. This error usually happens with Column(), Row(), Wrap(), Flex(), Stack() widgets which has multiple children.
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═════════════════
The following _TypeError was thrown building
Home(dirty, state: _HomeState#133d8):
type 'List<dynamic>' is not a subtype of type 'List<Widget>'
This error usually occurs when you want to pass the children widget using Map or List.
To solve this error, you can simply put <Widget> on List loop on children parameter of any widget like below:
children:mapdata.map<Widget>(
For example: change the loop through the map on children parameter like below:
Column(
children:mapdata.map((element){
return Card(
child: ListTile(
//widget tree
),
);
}).toList(),
)
Change this code like below:
Column(
children:mapdata.map<Widget>((element){
return Card(
child: ListTile(
//widget tree
),
);
}).toList(),
)
Here, we have added <Widget>
type on mapdata.map<Widget>
. Now, run your app, this error will not occur on your Flutter App.
Please Wait...
No any Comments on this Article