parseBoolean static method

bool parseBoolean({
  1. Object? value,
})

Parses a value into a boolean, supporting bool, 0/1, and 'true'/'false' strings.

Implementation

static bool parseBoolean({Object? value}) {
  if (value is bool) return value;
  final toint = IntUtils.tryParse(value);
  if (toint != null) {
    if (toint == 1) {
      return true;
    } else if (toint == 0) {
      return false;
    }
  } else {
    final str = value.toString().toLowerCase();
    if (str == 'true') {
      return true;
    } else if (str == 'false') {
      return false;
    }
  }
  throw BcsSerializationException(
      "Invalid value for move type 'Bool': Expected a boolean (true/false), a number (0/1), or a string ('true'/'false').",
      details: {"value": "$value"});
}