show static method

Future<PrismCommand?> show({
  1. required BuildContext context,
  2. required List<PrismCommand> commands,
  3. String placeholder = 'Type a command or search…',
  4. String? initialQuery,
})

Presents the palette as a route and resolves with the chosen command.

Implementation

static Future<PrismCommand?> show({
  required BuildContext context,
  required List<PrismCommand> commands,
  String placeholder = 'Type a command or search…',
  String? initialQuery,
}) {
  final tokens = PrismTokens.of(context);
  final narrow = MediaQuery.sizeOf(context).width < tokens.breakpointCompact;

  if (narrow) {
    return Navigator.of(context).push<PrismCommand>(
      MaterialPageRoute<PrismCommand>(
        fullscreenDialog: true,
        builder: (routeContext) => Scaffold(
          body: SafeArea(
            child: PrismCommandPalette(
              commands: commands,
              placeholder: placeholder,
              initialQuery: initialQuery ?? '',
              onCommandSelected: (c) => Navigator.of(routeContext).pop(c),
            ),
          ),
        ),
      ),
    );
  }

  return showDialog<PrismCommand>(
    context: context,
    barrierColor: Theme.of(context).colorScheme.scrim.withValues(alpha: 0.35),
    builder: (dialogContext) => Align(
      alignment: const Alignment(0, -0.55),
      child: Dialog(
        insetPadding: const EdgeInsets.symmetric(
          horizontal: 24,
          vertical: 48,
        ),
        backgroundColor: Colors.transparent,
        elevation: 0,
        child: ConstrainedBox(
          constraints: const BoxConstraints(maxWidth: 620, maxHeight: 520),
          child: PrismCommandPalette(
            commands: commands,
            placeholder: placeholder,
            initialQuery: initialQuery ?? '',
            onCommandSelected: (c) => Navigator.of(dialogContext).pop(c),
          ),
        ),
      ),
    ),
  );
}