From c880680c4e5856b4f86786b75bcd7b02e9211713 Mon Sep 17 00:00:00 2001 From: xubaolin Date: Sat, 24 Apr 2021 01:54:04 +0800 Subject: [PATCH] add a test for popupMenuButton (#80930) --- .../test/material/popup_menu_test.dart | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/packages/flutter/test/material/popup_menu_test.dart b/packages/flutter/test/material/popup_menu_test.dart index c7ebdd44b0..24c7aca130 100644 --- a/packages/flutter/test/material/popup_menu_test.dart +++ b/packages/flutter/test/material/popup_menu_test.dart @@ -2209,6 +2209,71 @@ void main() { await tester.pumpAndSettle(); expect(find.text('foo'), findsOneWidget); }); + + // Regression test for https://github.com/flutter/flutter/issues/80869 + testWidgets('The menu position test in the scrollable widget', (WidgetTester tester) async { + final GlobalKey buttonKey = GlobalKey(); + + await tester.pumpWidget( + MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: Column( + children: [ + const SizedBox(height: 100), + PopupMenuButton( + child: SizedBox( + key: buttonKey, + height: 10.0, + width: 10.0, + child: const ColoredBox( + color: Colors.pink, + ), + ), + itemBuilder: (BuildContext context) => >[ + const PopupMenuItem(child: Text('-1-'), value: 1,), + const PopupMenuItem(child: Text('-2-'), value: 2,), + ], + ), + const SizedBox(height: 600), + ], + ), + ), + ), + ), + ); + + // Open the menu. + await tester.tap(find.byKey(buttonKey)); + await tester.pumpAndSettle(); + + Offset button = tester.getTopLeft(find.byKey(buttonKey)); + expect(button, const Offset(0.0, 100.0)); + + Offset popupMenu = tester.getTopLeft(find.byType(SingleChildScrollView).last); + // The menu should be positioned directly next to the top of the button. + // The 8.0 pixels is [_kMenuScreenPadding]. + expect(popupMenu, const Offset(8.0, 100.0)); + + // Close the menu. + await tester.tap(find.byKey(buttonKey), warnIfMissed: false); + await tester.pumpAndSettle(); + + // Scroll a little bit. + await tester.drag(find.byType(SingleChildScrollView), const Offset(0.0, -50.0)); + + button = tester.getTopLeft(find.byKey(buttonKey)); + expect(button, const Offset(0.0, 50.0)); + + // Open the menu again. + await tester.tap(find.byKey(buttonKey)); + await tester.pumpAndSettle(); + + popupMenu = tester.getTopLeft(find.byType(SingleChildScrollView).last); + // The menu should be positioned directly next to the top of the button. + // The 8.0 pixels is [_kMenuScreenPadding]. + expect(popupMenu, const Offset(8.0, 50.0)); + }); } class TestApp extends StatefulWidget {