optInteger function

int optInteger(
  1. Map<String, dynamic> json,
  2. String fieldName
)

Calls through to {@link JSONObject#optInt(String)} only in the case that the key exists. This returns {@code null} if the key is not in the object.

@param jsonObject the input object @param fieldName the required field name @return the value stored in the requested field, or {@code null} if the key is not present

Implementation

int optInteger(Map<String, dynamic> json, String fieldName) {
  return json[fieldName] ?? 0;
}