M3EDropdownController<T> class
Controls an M3EDropdownMenu programmatically.
Provides methods to open/close the dropdown, select/deselect items, set items dynamically, and listen for changes.
Items are managed as immutable M3EDropdownItem instances. All mutations go through M3EDropdownItem.copyWith, which ensures the controller properly detects changes and notifies listeners.
Search filtering is handled internally — items returns either the full list or the filtered list depending on the active search query.
final controller = M3EDropdownController<String>();
Select items matching a condition
controller.selectWhere((item) => item.value == 'dart');
Clear all selections
controller.clearAll();
- Inheritance
-
- Object
- ChangeNotifier
- M3EDropdownController
Constructors
- M3EDropdownController()
- Creates a new M3EDropdownController.
Properties
-
disabledItems
→ List<
M3EDropdownItem< T> > -
The currently disabled items.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- initialized → bool
-
Whether initialize has been called by the widget.
no setter
- isDisposed → bool
-
Whether the controller has been disposed.
no setter
- isOpen → bool
-
Whether the dropdown is currently open.
no setter
-
items
→ List<
M3EDropdownItem< T> > -
The items visible to the dropdown list.
no setter
-
onSearchChange
↔ ValueChanged<
String> ? -
onSearchChange.
getter/setter pair
-
onSelectionChange
↔ ValueChanged<
List< ?M3EDropdownItem< >T> > -
onSelectionChange.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- searchQuery → String
-
The current search query (empty string when inactive).
no setter
-
selectedItems
→ List<
M3EDropdownItem< T> > -
The currently selected items.
no setter
-
selectedValues
→ List<
T> -
Convenience — the
Tvalues of the currently selected items.no setter
Methods
-
addItem(
M3EDropdownItem< T> item, {int index = -1}) → void -
Adds a single item. If
indexis provided, inserts at that position. -
addItems(
List< M3EDropdownItem< items) → voidT> > - Adds multiple items at the end of the list.
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
clearAll(
) → void - De-selects every item.
-
clearSearch(
) → void - Clears the current search query and shows all items.
-
clearSearchQuery(
{bool notify = false}) → void -
Clears the search query. If
notifyis true, listeners are notified. -
closeDropdown(
) → void - Closes the dropdown overlay and clears the search query.
-
disableWhere(
bool predicate(M3EDropdownItem< T> )) → void -
Disables items matching
predicate. -
dispose(
) → void -
Discards any resources used by the object.
override
-
enableWhere(
bool predicate(M3EDropdownItem< T> )) → void -
Enables items matching
predicate. -
initialize(
) → void - Marks the controller as initialized. Called once by the widget.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
override
-
openDropdown(
) → void - Opens the dropdown overlay.
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
selectAll(
) → void - Selects all non-disabled items.
-
selectAtIndex(
int index) → void -
Selects the item at the given
index. -
selectWhere(
bool predicate(M3EDropdownItem< T> )) → void -
Selects items matching
predicate. -
setItems(
List< M3EDropdownItem< items) → voidT> > - Replaces the entire item list, resetting the search query.
-
setOpen(
{required bool open}) → void - Sets the open state directly (used by the widget internally).
-
setSearchQuery(
String query) → void - Updates the search query, re-filters items, and fires the callback.
-
toggleDropdown(
) → void - Toggles the dropdown open/close state.
-
toggleOnly(
M3EDropdownItem< T> item) → void -
Selects only
item, deselecting all others (single-select helper). -
toggleWhere(
bool predicate(M3EDropdownItem< T> )) → void -
Toggles items matching
predicate. -
toString(
) → String -
A string representation of this object.
override
-
unselectWhere(
bool predicate(M3EDropdownItem< T> )) → void -
De-selects items matching
predicate.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited