parseInt static method

int? parseInt(
  1. Object? value, [
  2. int? def
])

Tries to parse an int.

  • Returns def if value is invalid.

Implementation

static int? parseInt(Object? value, [int? def]) {
  if (value == null) return def;

  if (value is int) {
    return value;
  } else if (value is num) {
    return value.toInt();
  } else if (value is DateTime) {
    return value.millisecondsSinceEpoch;
  } else {
    var n = _parseNumString(value);
    return n?.toInt() ?? def;
  }
}