coerceString function

String? coerceString(
  1. DartObject? value,
  2. String field, {
  3. String? defaultTo,
})

Reads and returns field on value as a string.

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

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

Implementation

String? coerceString(DartObject? value, String field, {String? defaultTo}) =>
    getField(value, field)?.toStringValue() ?? defaultTo;