parseBool function

bool? parseBool(
  1. String? value
)

Parses a string into a bool.

  • Accepts "true" or "false" (case‑insensitive).
  • Returns null if value is null or empty.
  • Throws Exception if the string is not valid.

Implementation

bool? parseBool(String? value) {
  if (value != null && value.isNotEmpty) {
    switch (value.toLowerCase()) {
      case "true":
        return true;
      case "false":
        return false;
      default:
        throw Exception("Problem parsing bool value: $value");
    }
  }
  return null;
}