How do I solve the 'Failed assertion: boolean expression must not be null' exception in Flutter

后端 未结 2 1308
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-11 20:48

I was working on a Flutter application and kept receiving this error String in the logcat.

Failed assertion: boolean expression must not be null
         


        
2条回答
  •  梦谈多话
    2021-01-11 21:09

    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.

提交回复
热议问题