requireInt function

int requireInt(
  1. CrossmintJsonMap map,
  2. String key, {
  3. required String entity,
})

Returns the integer at key in map, or throws a typed CrossmintDeserializationException naming entity and key.

Implementation

int requireInt(CrossmintJsonMap map, String key, {required String entity}) {
  final Object? value = map[key];
  if (value is int) {
    return value;
  }
  if (value is num) {
    return value.toInt();
  }
  throw CrossmintDeserializationException(
    'Expected integer for "$key" while parsing $entity.',
    entity: entity,
    field: key,
    cause: map,
  );
}