Booleans

To represent boolean values, Dart has a type named bool. Only twoobjects have type bool: the boolean literals true and false,which are both compile-time constants.

Dart’s type safety means that you can’t use code likeif (nonbooleanValue) orassert (nonbooleanValue).Instead, explicitly check for values, like this:

  1. // Check for an empty string.
  2. var fullName = '';
  3. assert(fullName.isEmpty);
  4. // Check for zero.
  5. var hitPoints = 0;
  6. assert(hitPoints <= 0);
  7. // Check for null.
  8. var unicorn;
  9. assert(unicorn == null);
  10. // Check for NaN.
  11. var iMeantToDoThis = 0 / 0;
  12. assert(iMeantToDoThis.isNaN);