Search field
Use a search field to narrow a collection by the words someone remembers. Keep the matches close to the query so it is clear what changed.
Find a title
#Type “field” to find two titles, then “travel” to find one. Delete the query to see all three again.
components/search-field/appliance/find_title.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class FindTitle extends StatefulWidget {
const FindTitle({super.key});
@override
State<FindTitle> createState() => _FindTitleState();
}
class _FindTitleState extends State<FindTitle> {
static const titles = ['Field notes', 'Field guide', 'Travel diary'];
String query = '';
Iterable<String> get matches =>
titles.where((title) => title.toLowerCase().contains(query));
void filter(String value) =>
setState(() => query = value.trim().toLowerCase());
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 360),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ApplianceSearchField(
semanticLabel: 'Find a title',
hint: 'Search titles',
onChanged: filter,
),
const SizedBox(height: 12),
Text(
matches.isEmpty ? 'No matching titles' : matches.join('\n'),
textAlign: TextAlign.center,
),
],
),
);
}
Parameters
ApplianceSearchField API ↗hint- Prompt shown before a query is entered.
onChanged- Filters the titles as the query changes.
Shared behaviour
- Keyboard and focus. Tab to search. If the look shows a search entry, activate it to reach the editor, then type. The list filters as you edit, so you can keep your place in the field.
- Screen readers. Read past the editable query to reach the matching titles. A query with no matches shows an explicit empty result.
- Direction and type. Try RTL and large text to inspect the search affordance and the wrapping titles.