Command constructor

const Command({
  1. Key? key,
  2. required CommandBuilder builder,
  3. bool autofocus = true,
  4. Duration debounceDuration = const Duration(milliseconds: 500),
  5. WidgetBuilder? emptyBuilder,
  6. ErrorWidgetBuilder? errorBuilder,
  7. WidgetBuilder? loadingBuilder,
  8. double? surfaceOpacity,
  9. double? surfaceBlur,
  10. 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 results
  • autofocus (bool, default: true): whether to auto-focus search input
  • debounceDuration (Duration, default: 500ms): debounce delay for search
  • emptyBuilder (WidgetBuilder?, optional): custom widget for empty state
  • errorBuilder (ErrorWidgetBuilder?, optional): custom error display
  • loadingBuilder (WidgetBuilder?, optional): custom loading indicator
  • surfaceOpacity (double?, optional): surface opacity override
  • surfaceBlur (double?, optional): surface blur override
  • searchPlaceholder (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,
});