build method

  1. @override
Widget build(
  1. BuildContext context
)
override

Describes the part of the UI represented by this widget.

Implementation

@override
Widget build(BuildContext context) {
  if (!open) return child;
  final theme = ThemeScope.of(context);

  // Blend the background content toward the backdrop color so the dialog
  // stands out while keeping the underlying content visible.
  final dimmedChild = backdropOpacity < 1.0 && backdropOpacity > 0.0
      ? Tint(
          color: backdropColor ?? theme.background,
          opacity: backdropOpacity,
          child: child,
        )
      : child;

  // Prevent pointer/scroll events from leaking to background content while
  // a modal is open. The dismiss layer and dialog remain interactive.
  final blockedBackground = _ModalInputBlocker(
    child: IgnorePointer(ignoring: true, child: dimmedChild),
  );

  // Transparent dismiss layer — sized to fill the stack but paints nothing,
  // so the dimmed child shows through.
  final dismissLayer = dismissible
      ? GestureDetector(onTap: () => onDismiss?.call(), child: Container())
      : Container();

  return Stack(
    fit: StackFit.expand,
    alignment: Alignment.center,
    children: [
      blockedBackground,
      Positioned(
        left: 0,
        right: 0,
        top: 0,
        bottom: 0,
        child: dismissLayer,
      ),
      Positioned(
        left: 0,
        right: 0,
        top: 0,
        bottom: 0,
        child: Center(child: FocusScope(isTrapped: true, child: dialog)),
      ),
    ],
  );
}