parseNonNegativeInt static method

int? parseNonNegativeInt(
  1. Object? raw
)

Implementation

static int? parseNonNegativeInt(Object? raw) {
  final value = switch (raw) {
    int() => raw,
    num() when raw.isFinite => raw.toInt(),
    String() => int.tryParse(raw.trim()),
    _ => null,
  };
  if (value == null || value < 0) return null;
  return value;
}