enumString<C extends Component, T extends Enum> static method

ComponentField<C> enumString<C extends Component, T extends Enum>(
  1. String name, {
  2. required List<T> values,
  3. required T defaultValue,
  4. T get(
    1. C component
    )?,
  5. void set(
    1. C component,
    2. T value
    )?,
  6. String? doc,
  7. String? group,
  8. List<String> formerNames = const [],
  9. bool transient = false,
})

An enum property carried as its value name string.

Implementation

static ComponentField<C> enumString<C extends Component, T extends Enum>(
  String name, {
  required List<T> values,
  required T defaultValue,
  T Function(C component)? get,
  void Function(C component, T value)? set,
  String? doc,
  String? group,
  List<String> formerNames = const [],
  bool transient = false,
}) => ComponentField(
  ComponentPropertyDef(
    name,
    ComponentPropertyKind.string,
    defaultValue: StringValue(defaultValue.name),
    doc: doc,
    group: group,
    options: [for (final value in values) value.name],
    formerNames: formerNames,
    transient: transient,
  ),
  read: get == null ? null : (c, _) => StringValue(get(c).name),
  write: set == null
      ? null
      : (c, v, _) {
          if (v is! StringValue) return;
          for (final value in values) {
            if (value.name == v.value) {
              set(c, value);
              return;
            }
          }
          debugPrint(
            'fscene: unrecognized $name value "${v.value}" on '
            '${c.runtimeType}; keeping ${get?.call(c).name ?? defaultValue.name}.',
          );
        },
);