toIntStrict function

IValidator toIntStrict(
  1. IValidator child, {
  2. String? message,
})

Strict integer coercion.

Accepts only:

  • Existing int values
  • Strings that are pure base-10 integers (no sign handling beyond leading '-' / '+').

Rejects:

  • double inputs (even if whole, e.g. 12.0)
  • Strings containing decimal points or exponent notation (e.g. "12.0", "1e3").

See also:

  • toInt – standard (allows doubles and int-like strings)
  • toIntSafe – strict + safe 53-bit range guard

Implementation

IValidator toIntStrict(IValidator child, {String? message}) {
  final base = ($isInt | $isIntString) &
      core.transform((v) {
        return switch (v) {
          final int n => n,
          final String s => int.tryParse(s.trim()),
          _ => null,
        };
      }, child);

  return handleReturnPreserveValue(base, message);
}