show<T> static method

Future<T?> show<T>(
  1. BuildContext context, {
  2. required Widget child,
  3. List<Widget> actionsRow = const [],
  4. List<Widget> actionsColumn = const [],
  5. double? height,
  6. Widget? header,
  7. bool useSafeArea = false,
  8. bool isScrollControlled = false,
  9. bool showCloseButton = false,
  10. EdgeInsets? headerPadding,
  11. Color? backgroundColor,
  12. bool showHandle = true,
  13. Color? closeButtonColor,
  14. Color? closeButtonIconColor,
  15. BoxDecoration? modalDecoration,
  16. Color? handleColor,
  17. bool useRootNavigator = true,
  18. Color? modalBackgroundColor,
})

Core method to display a modal bottom sheet with full customization.

context - BuildContext for showing the modal child - Main content widget to display in the modal actionsRow - List of action widgets displayed in a row actionsColumn - List of action widgets displayed in a column height - Optional fixed height for the modal header - Optional header widget positioned at the top useSafeArea - Whether to wrap content in SafeArea (default: true) isScrollControlled - Whether the modal can be scrolled (default: false) showCloseButton - Whether to show a close button (default: false) headerPadding - Padding for the main content when header is present backgroundColor - Background color of the modal showHandle - Whether to show the drag handle (default: true) closeButtonColor - Color of the close button background closeButtonIconColor - Color of the close button icon modalDecoration - Custom decoration for the modal container handleColor - Color of the drag handle useRootNavigator - Whether to use the root navigator (default: true) modalBackgroundColor - Background color of the modal content area

Implementation

static Future<T?> show<T>(
  BuildContext context, {
  required Widget child,
  List<Widget> actionsRow = const [],
  List<Widget> actionsColumn = const [],
  double? height,
  Widget? header,
  bool useSafeArea = false,
  bool isScrollControlled = false,
  bool showCloseButton = false,
  EdgeInsets? headerPadding,
  Color? backgroundColor,
  bool showHandle = true,
  Color? closeButtonColor,
  Color? closeButtonIconColor,
  BoxDecoration? modalDecoration,
  Color? handleColor,
  bool useRootNavigator = true,
  Color? modalBackgroundColor,
}) {
  return showModalBottomSheet<T>(
    context: context,
    useRootNavigator: useRootNavigator,
    isScrollControlled: isScrollControlled,
    useSafeArea: useSafeArea,
    backgroundColor:
        backgroundColor ??
        (header == null ? Colors.white : Colors.transparent),
    builder: (context) {
      Widget mainWidget = NyModalLayout(
        height: height,
        showHandle: header == null && showHandle,
        actionsRow: actionsRow,
        actionsColumn: actionsColumn,
        decoration: modalDecoration,
        handleColor: handleColor,
        backgroundColor: modalBackgroundColor,
        child: child,
      );

      if (header != null) {
        mainWidget = Stack(
          children: [
            Padding(
              padding: headerPadding ?? const EdgeInsets.only(top: 25),
              child: mainWidget,
            ),
            Positioned(top: 0, left: 0, right: 0, child: header),
            if (showCloseButton)
              Positioned(
                top: 20,
                right: 25,
                child: Container(
                  height: 35,
                  width: 35,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    color: closeButtonColor ?? const Color(0xFF484848),
                    borderRadius: BorderRadius.circular(40),
                  ),
                  child: IconButton(
                    padding: EdgeInsets.zero,
                    icon: Icon(
                      Icons.close,
                      color: closeButtonIconColor ?? Colors.white,
                      size: 20,
                    ),
                    onPressed: () {
                      Navigator.pop(context);
                    },
                  ),
                ),
              ),
          ],
        );
      }

      return mainWidget;
    },
  );
}