NestedMultiselectDropdown

A customizable Flutter widget that provides a nested, multi-level multiselect dropdown with support for hierarchical item selection, filtering, and external state management.

Features

  • Nested/hierarchical multiselect support
  • Customizable display text and styles
  • Selection filtering and parent-child selection tracking
  • Expandable and animated dropdown behavior
  • Controller to programmatically manage selection state
  • Custom check color and active color for checkboxes

Installation

Add to your pubspec.yaml:

dependencies:
  nested_multiselect_dropdown: <latest_version>

Then run:

flutter pub get

Usage

import 'package:nested_multiselect_dropdown/nested_multiselect_dropdown.dart';

final controller = NestedMultiselectDropdownController();

NestedMultiselectDropdown(
    options: yourOptionsList,
    controller: controller,
    isExpanded: true,
    onChange: (selectedItems) {
      print(selectedItems);
    },
);

API Reference

Required Parameters

  • options (List<NestedMultiselectDropdownItem>): The list of available items to display in the dropdown.
  • controller (NestedMultiselectDropdownController): A controller to programmatically interact with the dropdown (get selected items, clear selections, toggle expansion).

Optional Parameters

  • paddingSelectedItems (EdgeInsets, default: EdgeInsets.all(8)): Padding around the selected items displayed in the main container.
  • heightDropdownContainer (double, default: 50): Height of the dropdown container.
  • heightDropdownContainerDefault (double, default: 200): Default height for the animated container when expanded.
  • noItemsText (String, default: 'No Items Selected...'): Text to show when no items are selected.
  • noItemsTextStyle (TextStyle?): Custom text style for noItemsText.
  • onChange (Function(List<NestedMultiselectDropdownItem>)?): Callback triggered whenever selection changes.
  • isExpanded (bool, default: false): Whether the dropdown should take full width.
  • checkColor (Color?): Color of the checkbox checkmark.
  • activeColor (Color?): Background color of the active checkbox.
  • hasFilter (bool, default: false): Whether to show a filter checkbox in the dropdown.

Controller Methods

The NestedMultiselectDropdownController provides the following methods:

  • getSelectedItems(): Returns the current list of selected items.
  • expandContainer(): Expands or collapses the dropdown container.
  • clearValues(): Clears all selected values.

Example Item Model

NestedMultiselectDropdownItem(
    id: 1,
    name: "Fruits",
    children: [
        NestedMultiselectDropdownItem(id: 2, name: "Apple"),
        NestedMultiselectDropdownItem(id: 3, name: "Banana"),
    ],
)