Combobox
Use a combobox to choose a known item from a list that is easier to search than to scan. Keep the text being edited distinct from the choice that has been accepted.
Find a city
#Type “Li” and choose Lisbon or Lima. The destination below the field changes when you accept a suggestion.
components/combobox/appliance/find_city.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class FindCity extends StatefulWidget {
const FindCity({super.key});
@override
State<FindCity> createState() => _FindCityState();
}
class _FindCityState extends State<FindCity> {
String? city;
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 360),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ApplianceCombobox<String>(
label: 'Destination',
options: const ['Lima', 'Lisbon', 'Oslo'],
value: city,
onSelected: (option) => setState(() => city = option),
),
const SizedBox(height: 12),
Text(city == null ? 'No destination chosen' : 'Destination: $city'),
],
),
);
}
Parameters
ApplianceCombobox API ↗label- Names the field.
options- The three city suggestions.
onSelected- Commits the chosen city to the destination.
Shared behaviour
- Keyboard and focus. Tab to the editable field. Type to filter, move through suggestions with the arrows and press Enter to choose. Try Escape with the list open.
- Screen readers. Listen for the editable query and the available options. Read the destination below the field for the committed city.
- Direction and type. The list opens beside the field in the current direction. Try larger type in the phone frame with the suggestions open.