basicTypeToInt function

int? basicTypeToInt(
  1. Object? value
)

true as 1, false as 0, null as null, rounded to int

Implementation

int? basicTypeToInt(Object? value) {
  /// But most likely to happen first
  if (value is int) {
    // Infinity is an int on the web.
    return value.isFinite ? value : null;
  } else if (value == null) {
    return null;
  } else if (value is num) {
    // NaN and infinity cannot be rounded.
    return value.isFinite ? value.round() : null;
  } else if (value is bool) {
    return value ? 1 : 0;
  } else if (value is String) {
    return _parseInt(value);
  } else {
    return _parseInt(value.toString());
  }
}