Command constructor
const
Command({
- Key? key,
- required CommandBuilder builder,
- bool autofocus = true,
- Duration debounceDuration = const Duration(milliseconds: 500),
- WidgetBuilder? emptyBuilder,
- ErrorWidgetBuilder? errorBuilder,
- WidgetBuilder? loadingBuilder,
- double? surfaceOpacity,
- double? surfaceBlur,
- Widget? searchPlaceholder,
Creates a Command palette.
The builder
function receives the current search query and should return
a stream of widgets representing the filtered results.
Parameters:
builder
(CommandBuilder, required): async builder for search resultsautofocus
(bool, default: true): whether to auto-focus search inputdebounceDuration
(Duration, default: 500ms): debounce delay for searchemptyBuilder
(WidgetBuilder?, optional): custom widget for empty stateerrorBuilder
(ErrorWidgetBuilder?, optional): custom error displayloadingBuilder
(WidgetBuilder?, optional): custom loading indicatorsurfaceOpacity
(double?, optional): surface opacity overridesurfaceBlur
(double?, optional): surface blur overridesearchPlaceholder
(Widget?, optional): placeholder text for search input
Example:
Command(
autofocus: false,
debounceDuration: Duration(milliseconds: 200),
searchPlaceholder: Text('Search commands...'),
builder: (context, query) async* {
final filtered = commands.where((cmd) =>
cmd.name.toLowerCase().contains(query?.toLowerCase() ?? '')
);
yield filtered.map((cmd) => CommandItem(
child: Text(cmd.name),
onSelected: () => cmd.execute(),
)).toList();
},
)
Implementation
const Command({
super.key,
required this.builder,
this.autofocus = true,
this.debounceDuration = const Duration(milliseconds: 500),
this.emptyBuilder,
this.errorBuilder,
this.loadingBuilder,
this.surfaceOpacity,
this.surfaceBlur,
this.searchPlaceholder,
});