showZdsBottomSheet<T> function

Future<T?> showZdsBottomSheet<T>(
  1. {required BuildContext context,
  2. required WidgetBuilder builder,
  3. Color? backgroundColor,
  4. Color? barrierColor = Colors.black54,
  5. double? maxHeight,
  6. double? maxWidth,
  7. double? bottomInset,
  8. bool isDismissible = true,
  9. bool enableDrag = true,
  10. bool useRootNavigator = false,
  11. bool enforceSheet = false,
  12. EdgeInsetsGeometry? contentPadding,
  13. PreferredSizeWidget headerBuilder(
    1. BuildContext
    )?,
  14. PreferredSizeWidget? bottomBuilder(
    1. BuildContext
    )?}
)

Shows a bottom sheet with Zds styling.

Uses a ZdsBottomSheet to build the bottom sheet contents. context and builder must not be null.

  • builder creates the ZdsBottomSheet.child.
  • backgroundColor sets ZdsBottomSheet.backgroundColor.
  • barrierColor argument is used to specify the color of the modal barrier that darkens everything below the dialog. If null, the default color Colors.black54 is used.
  • maxHeight sets ZdsBottomSheet.maxHeight. If not null, it must be greater than 0. The bottom sheet will not grow beyond the screen height excluding the top viewPadding even if a greater maxHeight value is declared. Defaults to MediaQuery.size.height - MediaQuery.viewPadding.top.
  • maxWidth sets maxWidth for the dialog.
  • bottomInset sets ZdsBottomSheet.bottomInset. Defaults to MediaQuery.viewPadding.bottom.
  • headerBuilder creates the ZdsBottomSheet.header. Typically a ZdsSheetHeader.
  • bottomBuilder creates the ZdsBottomSheet.bottom. Typically a ZdsBottomBar.
  • If isDismissible is set to true, then clicking outside the sheet content will close the sheet else nothing happens. Defaults to true.
  • If enableDrag is set to true, then sheet could be dragged down to close it, provided that the immediate child
  • contentPadding can be used to apply additional padding to the body is a scrollable content. Defaults to true.
  • useRootNavigator The useRootNavigator argument is used to determine whether to push the dialog to the Navigator furthest from or nearest to the given context. By default, useRootNavigator is false and the dialog route created by this method is pushed to the nearest navigator. It can not be null.
  • enforceSheet argument is used to show bottom sheet irrespective of the device type. Defaults to false.

Implementation

Future<T?> showZdsBottomSheet<T>({
  required BuildContext context,
  required WidgetBuilder builder,
  Color? backgroundColor,
  Color? barrierColor = Colors.black54,
  double? maxHeight,
  double? maxWidth,
  double? bottomInset,
  bool isDismissible = true,
  bool enableDrag = true,
  bool useRootNavigator = false,
  bool enforceSheet = false,
  EdgeInsetsGeometry? contentPadding,
  PreferredSizeWidget Function(BuildContext)? headerBuilder,
  PreferredSizeWidget? Function(BuildContext)? bottomBuilder,
}) {
  return enforceSheet || !context.isTablet()
      ? showMaterialModalBottomSheet<T>(
          context: context,
          barrierColor: barrierColor,
          isDismissible: isDismissible,
          closeProgressThreshold: 0.8,
          bounce: true,
          enableDrag: enableDrag,
          clipBehavior: Clip.antiAlias,
          shape: const RoundedRectangleBorder(
            borderRadius: BorderRadius.vertical(top: Radius.circular(15)),
          ),
          builder: (BuildContext context) {
            final PreferredSizeWidget? header = headerBuilder?.call(context);
            final PreferredSizeWidget? bottom = bottomBuilder?.call(context);
            final Widget child = builder.call(context);

            return ZdsBottomSheet(
              header: header,
              bottom: bottom,
              maxHeight: maxHeight,
              bottomInset: bottomInset,
              backgroundColor: backgroundColor,
              child: child,
            );
          },
        )
      : showDialog<T>(
          context: context,
          barrierColor: barrierColor,
          barrierDismissible: isDismissible,
          useRootNavigator: useRootNavigator,
          builder: (BuildContext context) {
            final PreferredSizeWidget? header = headerBuilder?.call(context);
            final PreferredSizeWidget? bottom = bottomBuilder?.call(context);
            Widget child = builder.call(context);

            if (contentPadding != null) {
              child = Padding(
                padding: contentPadding,
                child: child,
              );
            }

            final double shortestSide = MediaQuery.of(context).size.shortestSide;

            return Dialog(
              backgroundColor: backgroundColor,
              shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.all(Radius.circular(15)),
              ),
              child: ClipRRect(
                borderRadius: BorderRadius.circular(15),
                child: SizedBox(
                  width: maxWidth ?? (shortestSide * 0.75),
                  height: maxHeight ?? (shortestSide * 0.70),
                  child: Column(
                    children: <Widget>[
                      if (header != null) header,
                      Expanded(
                        child: child,
                      ),
                      if (bottom != null) bottom,
                    ],
                  ),
                ),
              ),
            );
          },
        );
}