coerceInt function

int coerceInt(
  1. DartObject? value,
  2. String field, {
  3. required int defaultTo,
})

Reads and returns field on value as an integer.

Unlike DartObject#getField, this also traverses super if available.

If the value is missing or is not a boolean, returns defaultTo.

Implementation

int coerceInt(DartObject? value, String field, {required int defaultTo}) =>
    getField(value, field)?.toIntValue() ?? defaultTo;