showSheet<T> static method

Future<T?> showSheet<T>({
  1. required BuildContext context,
  2. required List<T> items,
  3. required Widget itemBuilder(
    1. T item
    ),
  4. String? title,
})

Shows items on a wheel in a modal bottom sheet and completes with the item the user picks.

The sheet follows showGlassDatePicker: a header with a Cancel button, the optional title, and a Done button above a CupertinoPicker that builds each item with itemBuilder.

  • Done completes the returned future with the item under the selection band. If the user has not scrolled, that is the first item. If items is empty, Done completes with null.
  • Cancel, a tap on the barrier, the system back gesture, and a screen reader's dismiss action all complete it with null.

Screen readers read the wheel as one adjustable element, named by title when it is given, with the selected item as its value.

Implementation

static Future<T?> showSheet<T>({
  required BuildContext context,
  required List<T> items,
  required Widget Function(T item) itemBuilder,
  String? title,
}) {
  final capturedGlassTheme = GlassTheme.maybeOf(context)?.data;
  final capturedCupertinoTheme = CupertinoTheme.of(context);
  return showCupertinoModalPopup<T>(
    context: context,
    // Exposes the barrier's "Dismiss" action to screen readers, like the
    // package's other sheets and popovers.
    semanticsDismissible: true,
    builder: (modalContext) {
      Widget sheet = _GlassPickerSheet<T>(
        items: items,
        itemBuilder: itemBuilder,
        title: title,
      );
      sheet = DefaultTextStyle(
        style: capturedCupertinoTheme.textTheme.textStyle,
        child: CupertinoTheme(
          data: capturedCupertinoTheme,
          child: sheet,
        ),
      );
      if (capturedGlassTheme != null) {
        sheet = GlassTheme(
          data: capturedGlassTheme,
          child: sheet,
        );
      }
      return sheet;
    },
  );
}