toBoolNullable method

  1. @useResult
bool? toBoolNullable()

Converts a case-insensitive string of 'true' or 'false' to a boolean. Returns null if the string is empty or not 'true' or 'false'.

Implementation

@useResult
bool? toBoolNullable() {
  final String lower = toLowerCase();
  if (lower == 'true') {
    return true;
  }

  if (lower == 'false') {
    return false;
  }

  return null;
}