ControlledSelect<T> constructor

const ControlledSelect<T>({
  1. Key? key,
  2. SelectController<T>? controller,
  3. ValueChanged<T?>? onChanged,
  4. bool enabled = true,
  5. T? initialValue,
  6. Widget? placeholder,
  7. Widget? leading,
  8. Widget? trailing,
  9. Widget? indicatorIcon,
  10. bool filled = false,
  11. FocusNode? focusNode,
  12. BoxConstraints? constraints,
  13. BoxConstraints? popupConstraints,
  14. PopoverConstraint popupWidthConstraint = PopoverConstraint.anchorFixedSize,
  15. BorderRadiusGeometry? borderRadius,
  16. EdgeInsetsGeometry? padding,
  17. AlignmentGeometry popoverAlignment = Alignment.topCenter,
  18. AlignmentGeometry? popoverAnchorAlignment,
  19. bool disableHoverEffect = false,
  20. bool canUnselect = false,
  21. bool autoClosePopover = true,
  22. Widget? expandIcon = const SelectExpandIcon(),
  23. required SelectPopupBuilder popup,
  24. required SelectValueBuilder<T> itemBuilder,
  25. SelectValueSelectionHandler<T>? valueSelectionHandler,
  26. SelectValueSelectionPredicate<T>? valueSelectionPredicate,
  27. Predicate<T>? showValuePredicate,
})

Creates a ControlledSelect.

Either controller or onChanged should be provided for interactivity. The widget supports both controller-based and callback-based state management patterns depending on application architecture needs.

Parameters:

  • controller (SelectController<T>?, optional): external state controller
  • initialValue (T?, optional): starting selection when no controller
  • onChanged (ValueChanged<T?>?, optional): selection change callback
  • enabled (bool, default: true): whether select is interactive
  • placeholder (Widget?, optional): widget shown when no item selected
  • leading (Widget?, optional): widget displayed before the selected value
  • trailing (Widget?, optional): widget displayed after the selected value
  • indicatorIcon (Widget?, optional): widget displayed as the dropdown indicator
  • filled (bool, default: false): whether to use filled appearance
  • focusNode (FocusNode?, optional): custom focus node for keyboard handling
  • constraints (BoxConstraints?, optional): size constraints for select widget
  • popupConstraints (BoxConstraints?, optional): size constraints for popup
  • popupWidthConstraint (PopoverConstraint, default: anchorFixedSize): popup width behavior
  • borderRadius (BorderRadiusGeometry?, optional): override select border radius
  • padding (EdgeInsetsGeometry?, optional): override internal padding
  • popoverAlignment (AlignmentGeometry, default: topCenter): popup alignment
  • popoverAnchorAlignment (AlignmentGeometry?, optional): anchor alignment
  • disableHoverEffect (bool, default: false): disable item hover effects
  • canUnselect (bool, default: false): allow deselecting current item
  • autoClosePopover (bool, default: true): close popup after selection
  • popup (SelectPopupBuilder, required): builder for popup content
  • itemBuilder (SelectItemBuilder<T>, required): builder for individual items
  • valueSelectionHandler (SelectValueSelectionHandler<T>?, optional): custom selection logic
  • valueSelectionPredicate (SelectValueSelectionPredicate<T>?, optional): selection validation
  • showValuePredicate (Predicate<T>?, optional): visibility filter for values
  • expandIcon (Widget): The expand icon for the select, defaults to SelectExpandIcon widget

Example:

ControlledSelect<String>(
  controller: controller,
  popup: (context, items) => ListView(children: items),
  itemBuilder: (context, item, selected) => Text(item),
  placeholder: Text('Select option'),
)

Implementation

const ControlledSelect({
  super.key,
  this.controller,
  this.onChanged,
  this.enabled = true,
  this.initialValue,
  this.placeholder,
  this.leading,
  this.trailing,
  this.indicatorIcon,
  this.filled = false,
  this.focusNode,
  this.constraints,
  this.popupConstraints,
  this.popupWidthConstraint = PopoverConstraint.anchorFixedSize,
  this.borderRadius,
  this.padding,
  this.popoverAlignment = Alignment.topCenter,
  this.popoverAnchorAlignment,
  this.disableHoverEffect = false,
  this.canUnselect = false,
  this.autoClosePopover = true,
  this.expandIcon = const SelectExpandIcon(),
  required this.popup,
  required this.itemBuilder,
  this.valueSelectionHandler,
  this.valueSelectionPredicate,
  this.showValuePredicate,
});