Exception thrown by widgets library '!children.any((Widget child) => child == null)': is not true

5,921

Solution 1

Faced the same problem a few days ago.

This happens when you forget to or miss to return the Widget.

Without seeing your code it's difficult to know the exact point of failure.

As far I am concerned, my previous code goes like:

@override
Widget build(BuildContext context) {
//....

  new Column(
  //.....
  );
}

And after fixing it::

@override
Widget build(BuildContext context) {
//....

  return new Column(
  //.....
  );
}

Hope this helps!

Solution 2

Might also get this problem if there is null in list of widgets:

Widget build() {
  return new Column(
    children: [
      new Title(),
      new Body(),
      shouldShowFooter ? null : new Container()
    ]
  );
}

To solve this:

bool notNull(Object o) => o != null;
Widget build() {
  return new Column(
    children: <Widget>[
      new Title(),
      new Body(),
      shouldShowFooter ? new Footer() : new Container()
    ].where(notNull).toList(),
  );
}

More info on it: https://github.com/flutter/flutter/issues/3783

Share:
5,921
Chaythanya Nair
Author by

Chaythanya Nair

Updated on December 04, 2022

Comments

  • Chaythanya Nair
    Chaythanya Nair over 1 year

    Hi I am getting the following error while running the application What can be the possible reason for the issue?

    ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
    The following assertion was thrown building Home(dirty, state: _HomeState#f7a67):
    'package:flutter/src/widgets/framework.dart': Failed assertion: line 1639: '!children.any((Widget
    child) => child == null)': is not true. 
    • Günter Zöchbauer
      Günter Zöchbauer about 6 years
      What code causes this exception? Sounds like you're passing a list of widgets somewhere where one or more of the items in the list are null
    • Hemanth Raj
      Hemanth Raj about 6 years
      More detailes required to resolve the problem. Can you share some code if possible, especially the List causing the issue. Thank You