show<T> method

Future<T?> show<T>({
  1. required BuildContext context,
  2. VoidCallback? onDismissRequest,
  3. bool isScrollControlled = true,
  4. bool useRootNavigator = false,
  5. RouteSettings? routeSettings,
})

Display this OudsModalBottomSheet as a modal dialog.

Wraps Flutter's showModalBottomSheet with OUDS theming applied.

Parameters

  • context – The build context used to look up the Navigator.
  • onDismissRequest – Optional callback invoked when the sheet is dismissed.
  • isScrollControlled – Whether the sheet height is controlled by its content (default true). Maps to showModalBottomSheet.isScrollControlled.
  • useRootNavigator – Whether to use the root navigator (default false).
  • routeSettings – Optional route settings passed to the modal route.

Implementation

Future<T?> show<T>({
  required BuildContext context,
  VoidCallback? onDismissRequest,
  bool isScrollControlled = true,
  bool useRootNavigator = false,
  RouteSettings? routeSettings,
}) {
  final theme = OudsTheme.of(context);
  final colorScheme = theme.colorScheme(context);
  final contentColor = colorScheme.contentDefault;

  final bottomSheetTheme = OudsBottomSheetThemeHelper.buildThemeData(context);

  return showModalBottomSheet<T>(
    context: context,
    backgroundColor: bottomSheetTheme.modalBackgroundColor,
    barrierColor: bottomSheetTheme.modalBarrierColor,
    shape: bottomSheetTheme.shape,
    elevation: bottomSheetTheme.modalElevation,
    clipBehavior: bottomSheetTheme.clipBehavior,
    isDismissible: true,
    enableDrag: sheetGesturesEnabled,
    showDragHandle: false,
    isScrollControlled: isScrollControlled,
    useRootNavigator: useRootNavigator,
    routeSettings: routeSettings,
    constraints: BoxConstraints(
      maxHeight:
          (MediaQuery.of(context).size.height -
              MediaQuery.of(context).padding.top -
              kToolbarHeight) *
          OudsBottomSheetConstants.modalMaxHeightFraction,
    ),
    builder: (sheetContext) {
      return DefaultTextStyle(
        style: TextStyle(color: contentColor),
        child: IconTheme(
          data: IconThemeData(color: contentColor),
          child: Column(
            mainAxisSize: MainAxisSize.max,
            children: [
              if (dragHandle)
                OudsBottomSheetDefaults.dragHandle(
                  sheetContext,
                  onTap: () => Navigator.of(sheetContext).pop(),
                ),
              Expanded(child: builder(sheetContext)),
            ],
          ),
        ),
      );
    },
  ).whenComplete(() => onDismissRequest?.call());
}