close

[Solved] the element type ‘Listwidget’ can’t be assigned to the list type ‘Widget’

Hello Guys How are you all? Hope You all are fine. When I was trying to run my flutter app and suddenly I get the following error in my stack track. the element type ‘Listwidget’ can’t be assigned to the list type ‘Widget’ in a flutter. So today Here I come with all possible solutions for this error.

We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.

How the element type ‘Listwidget’ can’t be assigned to the list type ‘Widget’ Error Occurs ?

I have Users List. I am making userTile for number of users found in for loop. Here is my code.

List<Widget> getUserList() {
  List<Widget> data = [];
  for (var i = 0; i < 10; i++) {
    data.add(new ListItem('user_id' + $i));
  }
  return data;
}

here I am accessing getUserList

children: <Widget>[getUserList()],

But it is showing compile time error.

The element type 'List<widget>' can't be assigned to the list type 'Widget'

How to Solve the element type ‘Listwidget’ can’t be assigned to the list type ‘Widget’ Error?

  1. How to Solve the element type 'Listwidget' can't be assigned to the list type 'Widget' Error?

    to Solve the element type 'Listwidget' can't be assigned to the list type 'Widget' Error Just wrapping a list as list children: [getUserList()], This should be like this. children: getUserList(),

  2. the element type 'Listwidget' can't be assigned to the list type 'Widget'

    to Solve the element type 'Listwidget' can't be assigned to the list type 'Widget' Error Just wrapping a list as list children: [getUserList()], This should be like this. children: getUserList(),

Solution 1

Just wrapping a list as list

children: <Widget>[getUserList()],

This should be like this.

children: getUserList(),

Solution 2

Just use spread operator:

children: <Widget>[...getUserList()]

Summery

So, It’s All About This Error. I hope this tutorial helps you to Solve your error. Please Comment Below if You stucks anywhere with my code. And please comment below on which solution worked for you. Thank You.

Also Check Out Below Tutorials

Leave a Comment

%d bloggers like this: