Skip to main content

Dropdown Select

C2CDropdownSelect is a customizable dropdown selection widget in Flutter. It allows for selection from a list of options and is highly customizable, supporting features like enabling/disabling the dropdown, custom styles, icons, error handling, and helper text.

Installation

cpub add c2c_select

or

flutter pub add c2c_select --hosted-url=https://pub.csp.scrum-dev.com

Example Usage

C2CDropdownSelect<String>(
items: const [
C2CSelectItem(label: 'Option 1', value: 'option_1'),
C2CSelectItem(label: 'Option 2', value: 'option_2')
],
value: 'option_1',
onChanged: (String? newValue) {
// Handle selection change
},
label: 'Select Option',
// Additional customizations
)

Properties

PropertyDescriptionType
itemsA list of C2CSelectItem objects representing the selectable items.List<C2CSelectItem<T>>
valueThe initial selected value.T?
onChangedCallback when a selection is made.ValueChanged<T?>?
enabledWhether the dropdown is enabled.bool
dropdownMaxHeightMaximum height of the dropdown menu.double?
enableFilterWhether the menu list can be filtered.bool
textStyleText style for the dropdown's TextField.TextStyle?
controllerController for managing the dropdown state.C2CSelectController?
dropdownBackgroundColorBackground color of the dropdown menu.Color?
dropdownBorderRadiusBorder radius for the dropdown menu.double?
itemTextStyleText style for dropdown items.TextStyle?
leftIconIcon displayed to the left of the dropdown.Widget?
rightIconIcon displayed to the right of the dropdown.Widget?
leftIconPaddingPadding for the left icon.EdgeInsets?
rightIconPaddingPadding for the right icon.EdgeInsets?
labelLabel displayed above the dropdown.dynamic
helperTextHelper text displayed below the dropdown.dynamic
errorError message displayed below the dropdown.dynamic
isRequiredWhether the dropdown is required.bool
labelStyleText style for the label.TextStyle?
asteriskStyleText style for the asterisk denoting a required field.TextStyle?
errorStyleText style for error messages.TextStyle?
helperStyleText style for helper text.TextStyle?
errorMaxLinesMaximum number of lines for error text.int?
helperMaxLinesMaximum number of lines for helper text.int?
scrollPaddingPadding to edges surrounding a Scrollable when the TextField scrolls into view.EdgeInsets?
onFocusCallback function called when the dropdown gains focus.VoidCallback?
onBlurCallback function called when the dropdown loses focus.VoidCallback?
borderRadiusBorder radius for the dropdown.BorderRadius?
selectItemBuilderBuilder function for customizing dropdown items.C2CSelectItemBuilder?
placeholderPlaceholder text displayed when no value is selected.String?
listControllerScroll controller for the dropdown menu.ScrollController?
checkboxColorColor of checkboxes in the dropdown.Color?
selectedItemBackgroundColorBackground color of the selected dropdown item.Color?
itemBackgroundColorBackground color of dropdown items.Color?

C2CSelectItem<T>

PropertyDescriptionType
labelThe text label displayed for the select item.String
labelStyleThe text style for the label.TextStyle?
valueThe value that this select item represents.T
disabledIndicates whether the item is disabled.bool

SelectType

SelectType is used to define the selection type (single or multiple) in selection widgets.

  • SelectType.single: For widgets that allow only single selection.
  • SelectType.multiple: For widgets that allow multiple selections.

C2CSelectItemBuilder<T>

typedef C2CSelectItemBuilder<T> = Widget Function(BuildContext context, T item, bool isSelected, Function() onChanged);
  • A builder function for customizing the appearance and behavior of select items.
  • Parameters:
    • context: The build context.
    • item: The item data.
    • isSelected: Indicates if the item is selected.
    • onChanged: Callback function to handle changes in item selection.

C2CSelectController

C2CSelectController is a controller class used to manage the state and behavior of a dropdown widget

Key Methods

isOpen

  • Returns a boolean value indicating whether the dropdown is currently open.
  • Usage: controller.isOpen

open

  • Opens the dropdown programmatically.
  • Ensures that the _anchor is not null before performing the action.
  • Usage: controller.open()

close

  • Closes the dropdown programmatically.
  • Ensures that the _anchor is not null before performing the action.
  • Usage: controller.close()

Example Usage

final C2CSelectController controller = C2CSelectController();

// To open the dropdown
controller.open();

// To close the dropdown
controller.close();

// To check if the dropdown is open
bool isDropdownOpen = controller.isOpen;