showMinimalBottomSheet<T> function

Future<T?> showMinimalBottomSheet<T>(
  1. BuildContext context, {
  2. String? title,
  3. String? subtitle,
  4. required WidgetBuilder builder,
  5. bool floating = true,
  6. MinimalSheetAction? leading,
  7. MinimalSheetAction? trailing,
  8. Widget? accessory,
})

Present a transient modal sheet from a control — a picker, a filter, a short create form — over the whole app, on the root navigator. A page declared as a sheet is raised by MinimalSheetPage instead, and its close is derived.

The card rises from the bottom on a spring with no overshoot (settling in about MinimalChromeMetrics.sheetIn) over a dimmed page, rides as low as its content is tall, and lifts with the keyboard so a sheet that edits never hides its own field. On a window wider than MinimalBottomSheet.centredWidth it stands centred at that width, as a dialog does, rather than spanning the window. A drag moves it with the finger (its content, scrolled to its top, hands the drag on), and let go low enough or flung down it closes; a tap on the scrim or Escape closes it too, and focus goes back to the control that raised it. floating: false presents the edge-attached drawer instead. The route is ui_core's (DesignBottomSheetRoute); Minimal paints the card.

await showMinimalBottomSheet<void>(context, title: 'New habit', subtitle: 'Habits', trailing: MinimalSheetAction('Create habit', onPressed: create, isDefaultAction: true), builder: (context) => form);

Implementation

Future<T?> showMinimalBottomSheet<T>(
  BuildContext context, {
  String? title,
  String? subtitle,
  required WidgetBuilder builder,
  bool floating = true,
  MinimalSheetAction? leading,
  MinimalSheetAction? trailing,
  Widget? accessory,
}) {
  final t = context.minimalTheme;
  final gap = floating ? MinimalBottomSheet.bottomGap(context) : 0.0;
  final maxHeight = MinimalBottomSheet.cap(context, floating: floating);
  final navigator = Navigator.of(context, rootNavigator: true);
  // The root navigator may stand above the page's own scopes, so the tokens
  // travel with the sheet.
  final themes = InheritedTheme.capture(from: context, to: navigator.context);
  return navigator.push<T>(
    DesignBottomSheetRoute<T>(
      barrierColor: t.overlay,
      barrierLabel: MinimalLocalizations.of(context).dismiss,
      semanticLabel: title,
      dampingRatio: MinimalChromeMetrics.routeDamping,
      stiffness: MinimalChromeMetrics.sheetStiffness,
      // The cap applies to the card inside its bottom gap, exactly as
      // [MinimalBottomSheet.pageRoute] applies it, so a shown card and a
      // sheet page of the same content stand the same height. On a wide
      // window the card stands centred, at most
      // [MinimalBottomSheet.centredWidth] wide.
      builder: (sheetContext, details) => themes.wrap(
        MinimalBottomSheet._rising(
          floating: floating,
          gap: gap,
          child: ConstrainedBox(
            constraints: BoxConstraints(maxHeight: maxHeight),
            child: MinimalBottomSheet(
              title: title,
              subtitle: subtitle,
              leading: leading,
              trailing: trailing,
              accessory: accessory,
              floating: floating,
              safe: !floating,
              child: SingleChildScrollView(
                controller: details.scrollController,
                child: builder(sheetContext),
              ),
            ),
          ),
        ),
      ),
    ),
  );
}