letBoolOrNull function

bool? letBoolOrNull(
  1. dynamic input
)

Let's you convert input to a bool type if possible, or returns null if the conversion cannot be performed.

Implementation

bool? letBoolOrNull(dynamic input) {
  if (input is bool) return input;
  if (input is num) return input == 1;
  if (input is String) return input.trim().toLowerCase() == 'true';
  return null;
}