show<R> static method

Future<DialogSelectItem<R>?> show<R>(
  1. BuildContext context, {
  2. required List<DialogSelectItem<R>> items,
  3. String? title,
  4. String? searchHint,
  5. void onSelect(
    1. DialogSelectItem<R> item
    )?,
  6. int? width,
  7. int? height,
  8. List<({String description, String key})> keybinds = const [],
  9. Widget trailing(
    1. int filteredCount,
    2. int totalCount
    )?,
  10. void onHighlightChanged(
    1. DialogSelectItem<R> item
    )?,
  11. Widget emptyBuilder(
    1. String searchQuery
    )?,
  12. bool barrierDismissible = true,
  13. Color? barrierColor,
  14. AnimationStyle? animationStyle,
})

Shows a DialogSelect in a modal dialog route.

Returns a Future that resolves to the selected DialogSelectItem or null if the dialog is dismissed without selection.

final selected = await DialogSelect.show<String>(
  context,
  title: 'Select Model',
  items: models.map((m) => DialogSelectItem(
    label: m.name,
    value: m.id,
  )).toList(),
);
if (selected != null) { ... }

Implementation

static Future<DialogSelectItem<R>?> show<R>(
  BuildContext context, {
  required List<DialogSelectItem<R>> items,
  String? title,
  String? searchHint,
  void Function(DialogSelectItem<R> item)? onSelect,
  int? width,
  int? height,
  List<({String key, String description})> keybinds = const [],
  Widget Function(int filteredCount, int totalCount)? trailing,
  void Function(DialogSelectItem<R> item)? onHighlightChanged,
  Widget Function(String searchQuery)? emptyBuilder,
  bool barrierDismissible = true,
  Color? barrierColor,
  AnimationStyle? animationStyle,
}) {
  return Navigator.of(context).showDialog<DialogSelectItem<R>>(
    barrierDismissible: barrierDismissible,
    barrierColor: barrierColor,
    animationStyle: animationStyle,
    builder: (ctx) => DialogSelect<R>(
      items: items,
      title: title,
      searchHint: searchHint,
      onSelect: (item) {
        Navigator.of(ctx).pop(item);
        onSelect?.call(item);
      },
      onDismiss: barrierDismissible
          ? () {
              Navigator.of(ctx).pop();
              return null;
            }
          : null,
      width: width,
      height: height,
      keybinds: keybinds,
      trailing: trailing,
      onHighlightChanged: onHighlightChanged,
      emptyBuilder: emptyBuilder,
    ),
  );
}