SelectFormField<T> constructor

SelectFormField<T>({
  1. required String label,
  2. String description = '',
  3. required List<SelectOption<T>> options,
  4. T? initialValue,
  5. String? validator(
    1. T?
    )?,
  6. bool focused = false,
})

Creates a SelectFormField with the given options.

Implementation

SelectFormField({
  required super.label,
  super.description = '',
  required this.options,
  super.initialValue,
  super.validator,
  super.focused = false,
}) {
  if (initialValue != null) {
    final idx = options.indexWhere((opt) => opt.value == initialValue);
    if (idx != -1) {
      _selectedIndex = idx;
      value = options[idx].value;
    }
  } else if (options.isNotEmpty) {
    value = options[0].value;
  }
}