This commit is contained in:
parent
7ce0dce2e5
commit
3e069a433b
@ -1077,7 +1077,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
|
|||||||
void showButtonMenu() {
|
void showButtonMenu() {
|
||||||
final PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context);
|
final PopupMenuThemeData popupMenuTheme = PopupMenuTheme.of(context);
|
||||||
final RenderBox button = context.findRenderObject()! as RenderBox;
|
final RenderBox button = context.findRenderObject()! as RenderBox;
|
||||||
final RenderBox overlay = Overlay.of(context)!.context.findRenderObject()! as RenderBox;
|
final RenderBox overlay = Navigator.of(context)!.overlay!.context.findRenderObject()! as RenderBox;
|
||||||
final RelativeRect position = RelativeRect.fromRect(
|
final RelativeRect position = RelativeRect.fromRect(
|
||||||
Rect.fromPoints(
|
Rect.fromPoints(
|
||||||
button.localToGlobal(widget.offset, ancestor: overlay),
|
button.localToGlobal(widget.offset, ancestor: overlay),
|
||||||
|
@ -634,6 +634,89 @@ void main() {
|
|||||||
await testPositioningDownThenUp(tester, TextDirection.rtl, Alignment.bottomCenter, TextDirection.rtl, const Rect.fromLTWH(450.0, 500.0, 0.0, 0.0));
|
await testPositioningDownThenUp(tester, TextDirection.rtl, Alignment.bottomCenter, TextDirection.rtl, const Rect.fromLTWH(450.0, 500.0, 0.0, 0.0));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('PopupMenu positioning inside nested Overlay', (WidgetTester tester) async {
|
||||||
|
final Key buttonKey = UniqueKey();
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
appBar: AppBar(title: const Text('Example')),
|
||||||
|
body: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Overlay(
|
||||||
|
initialEntries: <OverlayEntry>[
|
||||||
|
OverlayEntry(
|
||||||
|
builder: (_) => Center(
|
||||||
|
child: PopupMenuButton<int>(
|
||||||
|
key: buttonKey,
|
||||||
|
itemBuilder: (_) => <PopupMenuItem<int>>[
|
||||||
|
const PopupMenuItem<int>(value: 1, child: Text('Item 1')),
|
||||||
|
const PopupMenuItem<int>(value: 2, child: Text('Item 2')),
|
||||||
|
],
|
||||||
|
child: const Text('Show Menu'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final Finder buttonFinder = find.byKey(buttonKey);
|
||||||
|
final Finder popupFinder = find.bySemanticsLabel('Popup menu');
|
||||||
|
await tester.tap(buttonFinder);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final Offset buttonTopLeft = tester.getTopLeft(buttonFinder);
|
||||||
|
expect(tester.getTopLeft(popupFinder), buttonTopLeft);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('PopupMenu positioning inside nested Navigator', (WidgetTester tester) async {
|
||||||
|
final Key buttonKey = UniqueKey();
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
appBar: AppBar(title: const Text('Example')),
|
||||||
|
body: Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Navigator(
|
||||||
|
onGenerateRoute: (RouteSettings settings) {
|
||||||
|
return MaterialPageRoute<dynamic>(
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Center(
|
||||||
|
child: PopupMenuButton<int>(
|
||||||
|
key: buttonKey,
|
||||||
|
itemBuilder: (_) => <PopupMenuItem<int>>[
|
||||||
|
const PopupMenuItem<int>(value: 1, child: Text('Item 1')),
|
||||||
|
const PopupMenuItem<int>(value: 2, child: Text('Item 2')),
|
||||||
|
],
|
||||||
|
child: const Text('Show Menu'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final Finder buttonFinder = find.byKey(buttonKey);
|
||||||
|
final Finder popupFinder = find.bySemanticsLabel('Popup menu');
|
||||||
|
await tester.tap(buttonFinder);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final Offset buttonTopLeft = tester.getTopLeft(buttonFinder);
|
||||||
|
expect(tester.getTopLeft(popupFinder), buttonTopLeft);
|
||||||
|
});
|
||||||
|
|
||||||
testWidgets('PopupMenu removes MediaQuery padding', (WidgetTester tester) async {
|
testWidgets('PopupMenu removes MediaQuery padding', (WidgetTester tester) async {
|
||||||
late BuildContext popupContext;
|
late BuildContext popupContext;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user