Dart 使用 bool 类型表示布尔值。
Dart 只有字面量 true and false 是布尔类型, 这两个对象都是编译时常量。
Dart 是强 bool 类型检查,只有 bool 类型的值是 true 才被认为是 true。
var s1 = true;bool s2 = true;// 验证是否布尔值print(s1 is bool); //trueprint(s2 is bool); //true
Dart 的类型安全意味着不能使用 if (_nonbooleanValue_) 或者 assert (_nonbooleanValue_)。 而是应该像下面这样,明确的进行值检查:
// 检查空字符串。var fullName = '';assert(fullName.isEmpty);// 检查 0 值。var hitPoints = 0;assert(hitPoints <= 0);// 检查 null 值。var unicorn;assert(unicorn == null);// 检查 NaN 。var iMeantToDoThis = 0 / 0;assert(iMeantToDoThis.isNaN);
