NIB / DOCUMENTATION
Command palette — NibComponents
Search actions, drill into a group, and keep a bounded recent history.
Open interactive viewGive commands stable identities
NibCommandAction carries id, label, optional subtitle, icon, shortcutLabel, group, children, onSelected, and disabled. Use stable unique ids: recent history stores ids and resolves them against the current action tree. An action with children drills down; a leaf performs the action.
Create draft increments one local counter. Choose folder opens a second level; Later folder changes a local label. No files or services are modified. Disabling Create draft leaves the other commands available.
Make matching predictable
The default filter matches a case-insensitive substring in label or subtitle. NibCommandActionFilter defines a custom predicate. The inspector switches between the default and case-insensitive label prefix matching: raft matches Create draft under substring matching but not prefix matching.
The predicate checks the current action set; it does not load remote commands or authorize them. Keep expensive work outside it. The query filters the current drill-down level, not an invented global search service.
Choose a shortcut that belongs to the host
The default opener is Cmd+K or Ctrl+K according to platform. openShortcut accepts a ShortcutActivator. The widget installs a global HardwareKeyboard handler while mounted, so focus does not have to be inside its child. Multiple mounted palettes with the same activator can conflict.
This preview uses Alt+Shift+P to avoid the website search shortcut, and provides Open commands. Mount only one active example at a time. shortcutLabel on an action is a display hint; it does not register the action’s shortcut.
// Also import package:flutter/services.dart.
NibCommandPalette(
openShortcut: const SingleActivator(
LogicalKeyboardKey.keyP, alt: true, shift: true,
),
actions: actions,
child: page,
)Record one result and bounded history
A leaf’s onSelected and the palette’s onActionSelected both fire. Put a business effect in one of them; use the other for observation if needed. The example increments its counter in the leaf and reports the selected id through the palette callback.
showRecent controls the Recent section; maxRecent bounds stored ids. NibCommandPaletteController.recentActionIds is unmodifiable and newest-first. recordUsed(id, maxRecent) supports explicit integration, but ordinary selections already record history. Use a non-negative limit.
Keep a controller outside build
Create NibCommandPaletteController in State. open, close, toggle, and isOpen control the surface; dispose it with its owner. Without an external controller the widget owns an internal one. The widget removes its global keyboard handler and overlay on disposal.
The search field takes focus when opened and previous focus is restored on closure. Arrows, Enter, Escape, and drill-down/back navigation are supported. placeholder and hintStyle affect the search hint; backgroundColor changes the card fill. This palette inserts into the nearest overlay; in the website it remains within the active preview. Its keyboard handler is still global while mounted.
Keep execution policy in the application
The palette does not provide authorization, persistence, backend idempotency, or command cancellation. Recheck permissions at dispatch for an operation affecting real data. A displayed disabled state is not a security check.
animated defaults to false; transition configures optional motion. Tests cover filtering, leaf selection, nested choices, history, and removal. Operating-system shortcut conflicts and screen-reader behavior still need platform checks. If an action runs twice, inspect duplicate callbacks and mounted global handlers.