valueAsInt<T extends int?> method
T
valueAsInt<T extends int?>(
- K key, {
- bool allowHex = false,
- bool allowDouble = false,
- T onError(
- JsonParserError err
- T onMissing()?,
- bool acceptSnakeCase = false,
- bool acceptCamelCase = false,
Implementation
T valueAsInt<T extends int?>(
K key, {
bool allowHex = false,
bool allowDouble = false,
T Function(JsonParserError err)? onError,
T Function()? onMissing,
/// Also accepts the snake_case or camel_case version of [key] when looking up JSON fields.
/// Only applicable when [K] is `String`.
bool acceptSnakeCase = false,
bool acceptCamelCase = false,
}) {
try {
final value = _checkItem<T>(
key,
onMissing,
acceptSnakeCase,
acceptCamelCase,
);
if (value == null) return value as T;
return JsonParser.valueAsInt<T>(
value,
allowDouble: allowDouble,
allowHex: allowHex,
);
} on JsonParserError catch (e) {
if (onError != null) return onError(e);
rethrow;
}
}