2
votes

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. 
3
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 nullGünter Zöchbauer
More detailes required to resolve the problem. Can you share some code if possible, especially the List causing the issue. Thank YouHemanth Raj

3 Answers

10
votes

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!

2
votes

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

0
votes

In my case, the result of buildChildrenis null, or one element in the returned list is null.

Column column = new Column(
  // center the children
  mainAxisAlignment: MainAxisAlignment.start,
  crossAxisAlignment: CrossAxisAlignment.stretch,
  children: buildChildren(context),
);