Skip to Content
Forui 0.15.0 is released 🎉

Select

A select displays a list of drop-down options for the user to pick from.

It is a form-field and can therefore be used in a form.

For multi selections, consider using a multi select.

For touch devices, a select tile group or select menu tile is generally recommended over this.

CLI

To generate and customize this style:

dart run forui style create select

Usage

FSelect(...)

FSelect<Locale>( items: { 'United States': Locale('en', 'US'), 'Canada': Locale('en', 'CA'), 'Japan': Locale('ja', 'JP'), }, controller: FSelectController<Locale>(vsync: this), style: FSelectStyle.inherit(...), label: const Text('Country'), description: const Text('Select your country of residence'), hint: 'Choose a country', format: (value) => value.toUpperCase(), onChange: (value) => print('Selected country: $value'), onSaved: (value) => print('Saved country: $value'), autovalidateMode: AutovalidateMode.onUserInteraction, builder: (context, style, state, child) => child, prefixBuilder: (context, style, states) => Icon(FIcons.globe), suffixBuilder: (context, style, states) => Icon(FIcons.arrowDown), popoverConstraints: const FAutoWidthPortalConstraints(maxHeight: 400), clearable: true, contentScrollHandles: true, );

FSelect.rich(...)

FSelect<String>.rich( controller: FSelectController<String>(vsync: this), style: FSelectStyle(...), label: const Text('Country'), description: const Text('Select your country of residence'), hint: 'Choose a country', format: (value) => value.toUpperCase(), onChange: (value) => print('Selected country: $value'), onSaved: (value) => print('Saved country: $value'), autovalidateMode: AutovalidateMode.onUserInteraction, builder: (context, style, state, child) => child, prefixBuilder: (context, style, states) => Icon(FIcons.globe), suffixBuilder: (context, style, states) => Icon(FIcons.arrowDown), popoverConstraints: const FAutoWidthPortalConstraints(maxHeight: 400), clearable: true, contentDivider: FItemDivider.none, contentScrollHandles: true, initialValue: 'ca', children: [ FSelectSection( label: const Text('North American Countries'), divider: FItemDivider.none, children: [ FSelectItem( title: const Text('United States'), divider: FItemDivider.none, value: 'us', ), FSelectItem( title: Text('Canada'), value: 'ca', ), ], ), FSelectItem( title: Text('Japan'), value: 'jp', ), ], );

FSelect.search(...)

FSelect<User>.search( items: { 'Bob Ross': User(firstName: 'Bob', lastName: 'Ross'), 'John Doe': User(firstName: 'John', lastName: 'Doe'), 'Mary Jane': User(firstName: 'Mary', lastName: 'Jane'), 'Peter Parker': User(firstName: 'Peter', lastName: 'Parker'), }, controller: FSelectController<User>(), style: FSelectStyle.inherit(...), label: const Text('User'), description: const Text('Search and select a user'), builder: (context, styles, child) => child!, format: (user) => '${user.firstName} ${user.lastName}', hint: 'Search users...', popoverConstraints: const FAutoWidthPortalConstraints(maxHeight: 400), clearable: true, autoHide: false, onChange: (value) => print('Selected country: $value'), initialValue: 'value', contentDivider: FItemDivider.none, contentScrollHandles: false, contentPhysics: const BouncingScrollPhysics(), contentEmptyBuilder: (context, style) => Text('No results'), filter: (query) async { // Fetch users based on search query return fetchUsers(query); }, contentBuilder: (context, style, users) => [ for (final user in users) FSelectItem(title: Text('${user.firstName} ${user.lastName}'), value: user), ], searchFieldProperties: FSelectSearchFieldProperties( autofocus: true, hint: 'Type to search...', ), contentLoadingBuilder: (context, style) => Text('Loading...'), contentErrorBuilder: (context, error, stackTrace) => Text('Error...'), );

FSelect.searchBuilder(...)

FSelect<User>.searchBuilder( controller: FSelectController<User>(), style: FSelectStyle.inherit(...), label: const Text('User'), description: const Text('Search and select a user'), builder: (context, styles, child) => child!, format: (user) => '${user.firstName} ${user.lastName}', hint: 'Search users...', popoverConstraints: const FAutoWidthPortalConstraints(maxHeight: 400), clearable: true, autoHide: false, onChange: (value) => print('Selected country: $value'), initialValue: 'value', contentDivider: FItemDivider.none, contentScrollHandles: false, contentPhysics: const BouncingScrollPhysics(), contentEmptyBuilder: (context, style) => Text('No results'), filter: (query) async { // Fetch users based on search query return fetchUsers(query); }, contentBuilder: (context, users) => [ for (final user in users) FSelectItem(title: Text('${user.firstName} ${user.lastName}'), value: user), ], searchFieldProperties: FSelectSearchFieldProperties( autofocus: true, hint: 'Type to search...', ), contentLoadingBuilder: (context, style) => Text('Loading...'), contentErrorBuilder: (context, error, stackTrace) => Text('Error...'), );

Examples

Detailed

Sections

Dividers

Searchable

Sync

Async

Async with Custom Loading

Async with Custom Error Handling

Behavior

Toggleable Items

Clearable

Custom Formatting

With Scroll Handles

Form

Last updated on