onInit method

  1. @override
void onInit()
override

Called immediately after the widget is allocated in memory. You might use this to initialize something for the controller.

Implementation

@override
void onInit() {
  super.onInit();
  optionMap = OptionMap<T>(options);
  selectedValue.value = defaultValue;

  // Initialize focus
  if (defaultFocusValue != null &&
      optionMap.containsValue(defaultFocusValue as T)) {
    focusedValue.value = defaultFocusValue;
    _scrollToFocus();
  } else if (optionMap.first != null) {
    focusedValue.value = optionMap.first!.value;
  }

  final effectiveCount = math.min(visibleOptionCount, options.length);
  visibleToIndex.value = effectiveCount;

  // Initialize input values
  for (final opt in options) {
    if (opt.type == SelectOptionType.input && opt.initialValue != null) {
      inputValues[opt.value] = opt.initialValue!;
    }
  }
}