intFromJson static method

int? intFromJson(
  1. Map<String, dynamic> json,
  2. String attribute, {
  3. int? defaultValue,
})

Implementation

static int? intFromJson(Map<String, dynamic> json, String attribute,
    {int? defaultValue}) {
  try {
    if (json[attribute] != null) {
      if (json[attribute] is int) {
        return json[attribute];
      }
      return int.parse(json[attribute]);
    }
    return defaultValue;
  } catch (e) {
    throw Exception('Error while parsing $attribute[$e]');
  }
}