decodeInt method

  1. @override
int decodeInt(
  1. dynamic e, {
  2. String? name,
})
override

Implementation

@override
int decodeInt(dynamic e, {String? name}) {
  try {
    return switch (e) {
      int() => e,
      double() when e.toInt() == e => e.toInt(),
      String() => int.parse(e),
      _ => throw CodecException.typeMismatch(int, e.runtimeType, name),
    };
  } on FormatException catch (_) {
    throw CodecException.typeMismatch(int, e.runtimeType, name);
  }
}