enumValue<T> static method

T? enumValue<T>(
  1. List<T> values,
  2. DataSource source,
  3. List<Object> key
)

Returns one of the values of the specified enum T, from the specified string.

The string must match the name of the enum value, excluding the enum type name (the part of its toString after the dot).

The first argument must be the values list for that enum; this is the list of values that is searched.

For example, enumValue<TileMode>(TileMode.values, source, ['tileMode']) ?? TileMode.clamp reads the tileMode key of source, and looks for the first match in TileMode.values, defaulting to TileMode.clamp if nothing matches; thus, the string mirror would return TileMode.mirror.

Implementation

static T? enumValue<T>(List<T> values, DataSource source, List<Object> key) {
  final String? value = source.v<String>(key);
  if (value == null) {
    return null;
  }
  for (int index = 0; index < values.length; index += 1) {
    if (value == values[index].toString().split('.').last) {
      return values[index];
    }
  }
  return null;
}