SelectFormField<T> constructor

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

Creates a SelectFormField with the given options.

Implementation

SelectFormField({
  super.key,
  required super.label,
  super.description = '',
  required this.options,
  super.initialValue,
  super.validator,
  super.focusNode,
  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;
  }
}