Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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. 
like image 392
Chaythanya Nair Avatar asked Dec 11 '25 08:12

Chaythanya Nair


2 Answers

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!

like image 112
Janhavi Avatar answered Dec 14 '25 01:12

Janhavi


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

like image 40
Nuts Avatar answered Dec 14 '25 00:12

Nuts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!