getInt method

int? getInt(
  1. String key, {
  2. int? defaultValue,
})

Reads a key value of int type from Map.

If the key is not present in the map or the value of the key is not of type int, it will return null.

Example:

Map<String, dynamic> map = {'id': 11, 'name': 'John Doe', 'age': 30};
print(map.getInt('id')); // 11
print(map.getInt('age')); // 30
print(map.getInt('address')); // null

Implementation

int? getInt(String key, {int? defaultValue}) =>
    containsKey(key) ? int.tryParse('${this[key]}') : defaultValue;