@@ -624,8 +624,7 @@ class _PopupMenuRouteLayout extends SingleChildLayoutDelegate {
624624 this .itemSizes,
625625 this .selectedItemIndex,
626626 this .textDirection,
627- this .topPadding,
628- this .bottomPadding,
627+ this .padding,
629628 );
630629
631630 // Rectangle of underlying button, relative to the overlay's dimensions.
@@ -642,11 +641,8 @@ class _PopupMenuRouteLayout extends SingleChildLayoutDelegate {
642641 // Whether to prefer going to the left or to the right.
643642 final TextDirection textDirection;
644643
645- // Top padding of unsafe area.
646- final double topPadding;
647-
648- // Bottom padding of unsafe area.
649- final double bottomPadding;
644+ // The padding of unsafe area.
645+ EdgeInsets padding;
650646
651647 // We put the child wherever position specifies, so long as it will fit within
652648 // the specified parent size padded (inset) by 8. If necessary, we adjust the
@@ -657,7 +653,7 @@ class _PopupMenuRouteLayout extends SingleChildLayoutDelegate {
657653 // The menu can be at most the size of the overlay minus 8.0 pixels in each
658654 // direction.
659655 return BoxConstraints .loose (constraints.biggest).deflate (
660- const EdgeInsets .all (_kMenuScreenPadding) + EdgeInsets . only (top : topPadding, bottom : bottomPadding) ,
656+ const EdgeInsets .all (_kMenuScreenPadding) + padding ,
661657 );
662658 }
663659
@@ -701,14 +697,15 @@ class _PopupMenuRouteLayout extends SingleChildLayoutDelegate {
701697
702698 // Avoid going outside an area defined as the rectangle 8.0 pixels from the
703699 // edge of the screen in every direction.
704- if (x < _kMenuScreenPadding)
705- x = _kMenuScreenPadding;
706- else if (x + childSize.width > size.width - _kMenuScreenPadding)
707- x = size.width - childSize.width - _kMenuScreenPadding;
708- if (y < _kMenuScreenPadding + topPadding)
709- y = _kMenuScreenPadding + topPadding;
710- else if (y + childSize.height > size.height - _kMenuScreenPadding - bottomPadding)
711- y = size.height - bottomPadding - _kMenuScreenPadding - childSize.height ;
700+ if (x < _kMenuScreenPadding + padding.left)
701+ x = _kMenuScreenPadding + padding.left;
702+ else if (x + childSize.width > size.width - _kMenuScreenPadding - padding.right)
703+ x = size.width - childSize.width - _kMenuScreenPadding - padding.right ;
704+ if (y < _kMenuScreenPadding + padding.top)
705+ y = _kMenuScreenPadding + padding.top;
706+ else if (y + childSize.height > size.height - _kMenuScreenPadding - padding.bottom)
707+ y = size.height - padding.bottom - _kMenuScreenPadding - childSize.height ;
708+
712709 return Offset (x, y);
713710 }
714711
@@ -723,8 +720,7 @@ class _PopupMenuRouteLayout extends SingleChildLayoutDelegate {
723720 || selectedItemIndex != oldDelegate.selectedItemIndex
724721 || textDirection != oldDelegate.textDirection
725722 || ! listEquals (itemSizes, oldDelegate.itemSizes)
726- || topPadding != oldDelegate.topPadding
727- || bottomPadding != oldDelegate.bottomPadding;
723+ || padding != oldDelegate.padding;
728724 }
729725}
730726
@@ -784,22 +780,27 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
784780 }
785781
786782 final Widget menu = _PopupMenu <T >(route: this , semanticLabel: semanticLabel);
787-
788- return Builder (
789- builder: (BuildContext context) {
790- final MediaQueryData mediaQuery = MediaQuery .of (context);
791- return CustomSingleChildLayout (
792- delegate: _PopupMenuRouteLayout (
793- position,
794- itemSizes,
795- selectedItemIndex,
796- Directionality .of (context),
797- mediaQuery.padding.top,
798- mediaQuery.padding.bottom,
799- ),
800- child: capturedThemes.wrap (menu),
801- );
802- },
783+ final MediaQueryData mediaQuery = MediaQuery .of (context);
784+ return MediaQuery .removePadding (
785+ context: context,
786+ removeTop: true ,
787+ removeBottom: true ,
788+ removeLeft: true ,
789+ removeRight: true ,
790+ child: Builder (
791+ builder: (BuildContext context) {
792+ return CustomSingleChildLayout (
793+ delegate: _PopupMenuRouteLayout (
794+ position,
795+ itemSizes,
796+ selectedItemIndex,
797+ Directionality .of (context),
798+ mediaQuery.padding,
799+ ),
800+ child: capturedThemes.wrap (menu),
801+ );
802+ },
803+ ),
803804 );
804805 }
805806}
0 commit comments