I was working on a Flutter application and kept receiving this error String in the logcat.
Failed assertion: boolean expression must not be null
The solution was a simple one, this line here:
Flex(
...
children: (list_two = null) ? [] :
...
)
Needed to have the children comparison be a boolean, which requires 2 equals signs.
Flex(
...
children: (list_two == null) ? [] :
...
)
While using Android studio and writing in Java, this would normally throw a compiler error and not run, but while writing in dart with the Flutter plugin (1.0 as of today, 2018-06-26) no compiler error is shown and we instead see a runtime error.
This problem occurs when one of your defined boolean type variable is not initialized with default value, and you try to use and assign it somewhere as value. example maybe you have you bool isEnabled
; is not defined as should bool isEnabled = false
; or bool isEnabled = true
; and you try to use it like readOnly: isEnabled,
To avoid these to ensure isEnabled
won't be null
. Here is a kind of example of how we can avoid these
bool isChecked = false;
Checkbox(
value: isChecked, // initialized with `true/false` also avoids the error,
onChanged ...
)