openDrawerOverlay<T> function

DrawerOverlayCompleter<T?> openDrawerOverlay<T>({
  1. required BuildContext context,
  2. required WidgetBuilder builder,
  3. required OverlayPosition position,
  4. bool expands = false,
  5. bool draggable = true,
  6. bool barrierDismissible = true,
  7. WidgetBuilder? backdropBuilder,
  8. bool useSafeArea = true,
  9. bool? showDragHandle,
  10. BorderRadiusGeometry? borderRadius,
  11. Size? dragHandleSize,
  12. bool transformBackdrop = true,
  13. double? surfaceOpacity,
  14. double? surfaceBlur,
  15. Color? barrierColor,
  16. AnimationController? animationController,
  17. bool autoOpen = true,
  18. BoxConstraints? constraints,
  19. AlignmentGeometry? alignment,
})

Opens a drawer overlay with comprehensive customization options.

Creates a modal drawer that slides in from the specified position with draggable interaction, backdrop transformation, and proper theme integration. Returns a completer that can be used to control the drawer lifecycle.

Features:

  • Configurable slide-in positions (left, right, top, bottom)
  • Draggable interaction with gesture support
  • Backdrop transformation and scaling effects
  • Safe area handling and proper theming
  • Dismissible barriers and custom backdrop builders

Parameters:

  • context (BuildContext, required): build context for overlay creation
  • builder (WidgetBuilder, required): function that builds drawer content
  • position (OverlayPosition, required): side from which drawer slides in
  • expands (bool, default: false): whether drawer should expand to fill available space
  • draggable (bool, default: true): whether drawer can be dragged to dismiss
  • barrierDismissible (bool, default: true): whether tapping barrier dismisses drawer
  • backdropBuilder (WidgetBuilder?, optional): custom backdrop builder
  • useSafeArea (bool, default: true): whether to respect device safe areas
  • showDragHandle (bool?, optional): whether to show drag handle
  • borderRadius (BorderRadiusGeometry?, optional): corner radius for drawer
  • dragHandleSize (Size?, optional): size of the drag handle
  • transformBackdrop (bool, default: true): whether to scale backdrop
  • surfaceOpacity (double?, optional): opacity for surface effects
  • surfaceBlur (double?, optional): blur intensity for surface effects
  • barrierColor (Color?, optional): color of the modal barrier
  • animationController (AnimationController?, optional): custom animation controller
  • autoOpen (bool, default: true): whether to automatically open on creation
  • constraints (BoxConstraints?, optional): size constraints for drawer
  • alignment (AlignmentGeometry?, optional): alignment within constraints

Returns: A DrawerOverlayCompleter that provides control over the drawer lifecycle.

Example:

final completer = openDrawerOverlay<String>(
  context: context,
  position: OverlayPosition.left,
  builder: (context) => DrawerContent(),
  draggable: true,
  barrierDismissible: true,
);
final result = await completer.future;

Implementation

DrawerOverlayCompleter<T?> openDrawerOverlay<T>({
  required BuildContext context,
  required WidgetBuilder builder,
  required OverlayPosition position,
  bool expands = false,
  bool draggable = true,
  bool barrierDismissible = true,
  WidgetBuilder? backdropBuilder,
  bool useSafeArea = true,
  bool? showDragHandle,
  BorderRadiusGeometry? borderRadius,
  Size? dragHandleSize,
  bool transformBackdrop = true,
  double? surfaceOpacity,
  double? surfaceBlur,
  Color? barrierColor,
  AnimationController? animationController,
  bool autoOpen = true,
  BoxConstraints? constraints,
  AlignmentGeometry? alignment,
}) {
  final theme = ComponentTheme.maybeOf<DrawerTheme>(context);
  showDragHandle ??= theme?.showDragHandle ?? true;
  surfaceOpacity ??= theme?.surfaceOpacity;
  surfaceBlur ??= theme?.surfaceBlur;
  barrierColor ??= theme?.barrierColor;
  dragHandleSize ??= theme?.dragHandleSize;
  return openRawDrawer<T>(
    context: context,
    barrierDismissible: barrierDismissible,
    backdropBuilder: backdropBuilder,
    useSafeArea: useSafeArea,
    transformBackdrop: transformBackdrop,
    animationController: animationController,
    autoOpen: autoOpen,
    constraints: constraints,
    alignment: alignment,
    builder: (context, extraSize, size, padding, stackIndex) {
      return DrawerWrapper(
        position: position,
        expands: expands,
        draggable: draggable,
        extraSize: extraSize,
        size: size,
        showDragHandle: showDragHandle ?? true,
        dragHandleSize: dragHandleSize,
        padding: padding,
        borderRadius: borderRadius,
        surfaceOpacity: surfaceOpacity,
        surfaceBlur: surfaceBlur,
        barrierColor: barrierColor,
        stackIndex: stackIndex,
        child: Builder(builder: (context) {
          return builder(context);
        }),
      );
    },
    position: position,
  );
}