Skip to main content

Overview

HuxDropdown is a versatile dropdown/select component that provides multiple visual variants, sizes, and supports custom item rendering with icons. It adapts seamlessly to light and dark themes.

Basic Usage

HuxDropdown<String>(
  items: [
    HuxDropdownItem(
      value: 'item1',
      child: Text('Item 1'),
    ),
    HuxDropdownItem(
      value: 'item2',
      child: Text('Item 2'),
    ),
  ],
  value: selectedValue,
  onChanged: (value) => setState(() => selectedValue = value),
  placeholder: 'Select option',
)

Variants

HuxDropdown supports four visual variants through the HuxButtonVariant enum:

Primary

The default variant with a filled background using the primary color. Primary Dropdown
HuxDropdown(
  items: [
    HuxDropdownItem(
      value: 'item1',
      child: Text('Item 1'),
    ),
    HuxDropdownItem(
      value: 'item2',
      child: Text('Item 2'),
    ),
  ],
  value: selectedValue,
  onChanged: (value) => setState(() => selectedValue = value),
  placeholder: 'Select option',
  variant: HuxButtonVariant.primary,
)

Secondary

A subtle variant with a light background and border. Secondary Dropdown
HuxDropdown(
  items: [
    HuxDropdownItem(
      value: 'item1',
      child: Text('Item 1'),
    ),
    HuxDropdownItem(
      value: 'item2',
      child: Text('Item 2'),
    ),
  ],
  value: selectedValue,
  onChanged: (value) => setState(() => selectedValue = value),
  placeholder: 'Select option',
  variant: HuxButtonVariant.secondary,
)

Outline

A transparent dropdown with only a border outline. Outline Dropdown
HuxDropdown(
  items: [
    HuxDropdownItem(
      value: 'item1',
      child: Text('Item 1'),
    ),
    HuxDropdownItem(
      value: 'item2',
      child: Text('Item 2'),
    ),
  ],
  value: selectedValue,
  onChanged: (value) => setState(() => selectedValue = value),
  placeholder: 'Select option',
  variant: HuxButtonVariant.outline,
)

Ghost

A minimal transparent dropdown without borders. Ghost Dropdown
HuxDropdown(
  items: [
    HuxDropdownItem(
      value: 'item1',
      child: Text('Item 1'),
    ),
    HuxDropdownItem(
      value: 'item2',
      child: Text('Item 2'),
    ),
  ],
  value: selectedValue,
  onChanged: (value) => setState(() => selectedValue = value),
  placeholder: 'Select option',
  variant: HuxButtonVariant.ghost,
)

States

Default

Shows the placeholder text when no value is selected. Dropdown Default
HuxDropdown<String>(
  items: [
    HuxDropdownItem(
      value: 'item1',
      child: Text('Item 1'),
    ),
    HuxDropdownItem(
      value: 'item2',
      child: Text('Item 2'),
    ),
  ],
  value: null,
  onChanged: (value) => setState(() => selectedValue = value),
  placeholder: 'Select option',
)

Expanded

Shows the dropdown panel with options. Dropdown Expanded
HuxDropdown<String>(
  items: [
    HuxDropdownItem(
      value: 'item1',
      child: Text('Item 1'),
    ),
    HuxDropdownItem(
      value: 'item2',
      child: Text('Item 2'),
    ),
    HuxDropdownItem(
      value: 'item3',
      child: Text('Item 3'),
    ),
  ],
  value: selectedValue,
  onChanged: (value) => setState(() => selectedValue = value),
  placeholder: 'Select option',
)

Selected

Shows the selected option. Dropdown Selected
HuxDropdown<String>(
  items: [
    HuxDropdownItem(
      value: 'item1',
      child: Text('Item 1'),
    ),
    HuxDropdownItem(
      value: 'item2',
      child: Text('Item 2'),
    ),
  ],
  value: 'Item 1',
  onChanged: (value) => setState(() => selectedValue = value),
  placeholder: 'Select option',
)

Disabled

Prevents user interaction. Dropdown Disabled
HuxDropdown<String>(
  items: [
    HuxDropdownItem(
      value: 'item1',
      child: Text('Item 1'),
    ),
    HuxDropdownItem(
      value: 'item2',
      child: Text('Item 2'),
    ),
  ],
  value: selectedValue,
  onChanged: null, // or enabled: false
  placeholder: 'Select option',
  enabled: false,
)

Sizes

HuxDropdown supports three size variants through the HuxButtonSize enum:

Small

Compact size for tight spaces (32px height). Small Dropdown
HuxDropdown<String>(
  items: [
    HuxDropdownItem(
      value: 'item1',
      child: Text('Item 1'),
    ),
    HuxDropdownItem(
      value: 'item2',
      child: Text('Item 2'),
    ),
  ],
  value: selectedValue,
  onChanged: (value) => setState(() => selectedValue = value),
  placeholder: 'Select option',
  size: HuxButtonSize.small,
)

Medium

Default size for most use cases (40px height). Medium Dropdown
HuxDropdown<String>(
  items: [
    HuxDropdownItem(
      value: 'item1',
      child: Text('Item 1'),
    ),
    HuxDropdownItem(
      value: 'item2',
      child: Text('Item 2'),
    ),
  ],
  value: selectedValue,
  onChanged: (value) => setState(() => selectedValue = value),
  placeholder: 'Select option',
  size: HuxButtonSize.medium, // Default
)

Large

Prominent size for important selections (48px height). Large Dropdown
HuxDropdown<String>(
  items: [
    HuxDropdownItem(
      value: 'item1',
      child: Text('Item 1'),
    ),
    HuxDropdownItem(
      value: 'item2',
      child: Text('Item 2'),
    ),
  ],
  value: selectedValue,
  onChanged: (value) => setState(() => selectedValue = value),
  placeholder: 'Select option',
  size: HuxButtonSize.large,
)

With Icons

Enhance dropdown items with icons. Dropdown with icons
HuxDropdown<String>(
  items: [
    HuxDropdownItem(
      value: 'user',
      child: Row(
        children: [
          Icon(FeatherIcons.user, size: 16),
          SizedBox(width: 8),
          Text('User'),
        ],
      ),
    ),
    HuxDropdownItem(
      value: 'settings',
      child: Row(
        children: [
          Icon(FeatherIcons.settings, size: 16),
          SizedBox(width: 8),
          Text('Settings'),
        ],
      ),
    ),
  ],
  value: selectedValue,
  onChanged: (value) => setState(() => selectedValue = value),
  placeholder: 'Select option',
)

Using Item Widget as Value

By default, HuxDropdown extracts and displays text from the selected item’s widget. The useItemWidgetAsValue parameter allows you to display the complete item widget (including icons, badges, and complex layouts) as the selected value.
HuxDropdown<String>(
  useItemWidgetAsValue: true, // Display full widget instead of just text
  items: [
    HuxDropdownItem(
      value: 'user',
      child: Row(
        children: [
          Icon(LucideIcons.user, size: 16),
          SizedBox(width: 8),
          Text('User'),
        ],
      ),
    ),
    HuxDropdownItem(
      value: 'settings',
      child: Row(
        children: [
          Icon(LucideIcons.settings, size: 16),
          SizedBox(width: 8),
          Text('Settings'),
        ],
      ),
    ),
  ],
  value: selectedValue,
  onChanged: (value) => setState(() => selectedValue = value),
  placeholder: 'Select option',
)
With this feature enabled, the selected value will show the complete widget with all its visual elements (icons, badges, custom layouts), providing a richer visual experience compared to text-only representation.

Custom Colors

Override the primary color of the dropdown. Custom Dropdown
HuxDropdown(
  primaryColor: Colors.purple,
  // ...
)

API Reference

HuxDropdown Properties

PropertyTypeDefaultDescription
itemsList<HuxDropdownItem<T>>requiredList of dropdown items
valueT?nullCurrently selected value
onChangedValueChanged<T>?nullCalled when selection changes
placeholderString'Select option'Text shown when no value is selected
variantHuxButtonVariantoutlineVisual style of the dropdown
sizeHuxButtonSizemediumSize of the dropdown
primaryColorColor?nullOptional primary color override
enabledbooltrueWhether the dropdown is enabled
maxHeightdouble200Maximum height of the dropdown panel
useItemWidgetAsValueboolfalseDisplay the complete item widget instead of extracting text

HuxDropdownItem Properties

PropertyTypeDefaultDescription
valueTrequiredThe value associated with this item
childWidgetrequiredThe widget to display for this item

Accessibility

HuxDropdown includes several accessibility features:

Automatic Contrast

Text color is automatically calculated to ensure WCAG AA compliance (4.5:1 contrast ratio) against any background color.

Keyboard Navigation

  • Arrow keys to navigate items
  • Enter/Space to open/close and select
  • Escape to close dropdown

Focus States

Proper focus management and visible focus indicators.

Semantic Labels

Clear labels and roles for screen readers.

Best Practices

  • Use Large for primary selection fields
  • Use Medium for most standard forms
  • Use Small for compact interfaces or filters
  • Use descriptive placeholders
  • Group related dropdowns logically
  • Consider adding helper text for complex selections
  • Keep items concise
  • Use icons to enhance visual scanning
  • Order items logically (e.g., alphabetically)

Examples