Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

A list of widgets is placed where Flutter expects one widget

ErrorThe element type 'List<Widget>' can't be assigned to the list type 'Widget'.

Short answer

Dart found a whole list inside a list literal that holds single widgets. Put the items in with the spread operator (...), so the list is unpacked instead of nested. The same applies to an if element that builds several widgets, and to the result of map(), which is an Iterable and needs a spread or toList().

  • Applies to Dart 3.x, Flutter 3.3x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the line the analyzer underlines and look at the value you pass. If it is a variable or method that returns a list, or a map(...) call, one of the causes below applies. The analyzer output lists every such line.

    flutter analyze
  2. 2Match what you see, then jump to its fix

    1. 1The element type 'List<Widget>' can't be assigned to the list type 'Widget'.A list sits inside children next to single widgetsFix
    2. 2The element type 'List<Widget>' can't be assigned to the list type 'Widget' on a line that starts with ifA collection if produces several widgets without a spreadFix
    3. 3The element type 'Iterable<Widget>' can't be assigned to the list type 'Widget'.map() returns an Iterable, not a list of widgetsFix
    4. 4Error on the spread line saying the value can't be nullThe list can be nullFix

What does the error look like?

  • The element type 'List<Widget>' can't be assigned to the list type 'Widget'.
  • The argument type 'List<Widget>' can't be assigned to the parameter type 'Widget'.
  • The element type 'Iterable<Widget>' can't be assigned to the list type 'Widget'.

Cause 1 of 4

A list sits inside children next to single widgets

1Check

children expects a list whose items are widgets. If one item is itself a list (a helper method such as buildButtons() that returns List<Widget>), the list is nested, and Dart rejects it.

grep -n "children:" -A8 lib/screens/home_screen.dart

2Fix

Add the spread operator in front of the list. It inserts each value of the list into the surrounding list.

Column(
  children: [
    const Text('Title'),
    ...buildButtons(),
    const Text('Footer'),
  ],
)

3Verify

The analyzer no longer reports the line.

flutter analyze

Confirmed by dart.dev

Did this fix it?

Cause 2 of 4

A collection if produces several widgets without a spread

1Check

An if element inside a list literal adds one element. If its branch is a list of widgets, that list is again nested.

grep -n "if (" -A4 lib/screens/home_screen.dart

2Fix

Write the spread directly inside the if element, so the branch adds several values.

Column(
  children: [
    if (isLoggedIn) ...[
      const Text('Welcome'),
      const Text('Your orders'),
    ],
    const Text('Footer'),
  ],
)

3Verify

Run the analyzer again.

flutter analyze

Confirmed by dart.dev

Did this fix it?

Cause 3 of 4

map() returns an Iterable, not a list of widgets

1Check

Iterable.map returns a lazy Iterable. Placing it as an item of children nests it, and passing it where a List<Widget> is required fails too.

grep -n ".map(" lib/screens/home_screen.dart

2Fix

Spread the mapped values into the list. When a real List<Widget> is needed, call toList() at the end.

Column(
  children: [
    ...items.map((item) => ListTile(title: Text(item.name))),
  ],
)

// when a List<Widget> is required:
final tiles = items.map((item) => ListTile(title: Text(item.name))).toList();

3Verify

Run the analyzer and open the screen.

flutter analyze

Confirmed by api.dart.dev

Did this fix it?

Cause 4 of 4

The list can be null

1Check

With null safety, a spread (...) on a value that might be null is not allowed.

grep -n "\.\.\." lib/screens/home_screen.dart

2Fix

Use the null-aware spread. It adds nothing when the list is null.

List<Widget>? extras;

Column(
  children: [
    const Text('Title'),
    ...?extras,
  ],
)

3Verify

Run the analyzer.

flutter analyze

Confirmed by dart.dev

Did this fix it?

How do I stop it coming back?

  • Make helper methods return a single Widget, or document clearly that they return a list and spread them at the call site.
  • Use ...[ ] inside if and for elements whenever a branch adds more than one widget.
  • Run flutter analyze before each commit so a nested list shows up as an error at once.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.