showOverlay<T> method

OverlayEntry showOverlay<T>({
  1. required Widget child,
  2. Alignment? alignment,
  3. double? fromTop,
  4. double? fromBottom,
  5. double? fromRight,
  6. double? fromLeft,
  7. bool canSizeOverlay = false,
  8. bool maintainState = false,
  9. bool opaque = false,
})

The alignment priority is higher than the others. To remove an overlay use the following code: overlayEntry.remove(); overlayEntry.dispose();

Implementation

OverlayEntry showOverlay<T>({
  required Widget child,
  Alignment? alignment,
  double? fromTop,
  double? fromBottom,
  double? fromRight,
  double? fromLeft,
  bool canSizeOverlay = false,
  bool maintainState = false,
  bool opaque = false,
}) {
  OverlayEntry overlayEntry = OverlayEntry(
    canSizeOverlay: canSizeOverlay,
    maintainState: maintainState,
    opaque: opaque,
    builder: (context) {
      return Stack(
        children: [
          Positioned(
            top: fromTop,
            bottom: fromBottom,
            right: fromRight,
            left: fromLeft,
            child: Material(
              type: MaterialType.transparency,
              child: Container(
                alignment: alignment,
                child: child,
              ),
            ),
          ),
        ],
      );
    },
  );

  Overlay.of(context, debugRequiredFor: child).insert(overlayEntry);
  return overlayEntry;
}