dart Failed assertion: boolean expression must not be null

 
 

Failed assertion: boolean expression must not be null出现这种情况是你的 if中的条件或者其他条件为null,如下两种条件,

原因貌似是在dart中bool的值只有 true 或者 false,所以 null不会被视为false ,同理 >1的数也不会视为true,反而会出现错误。

这大概和dart什么都是对象属性有关,bool值true fasle 也是对象,其他对象自然不能填入

dart官网原话:To represent boolean values, Dart has a type named bool. Only two objects have type bool: the boolean literals true and false, which are both compile-time constants.

if(条件)

条件?doOne():doTwo()

猜你喜欢

转载自blog.csdn.net/qq_32319999/article/details/80667336