add a test for popupMenuButton (#80930)
This commit is contained in:
@@ -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: <Widget>[
|
||||
const SizedBox(height: 100),
|
||||
PopupMenuButton<int>(
|
||||
child: SizedBox(
|
||||
key: buttonKey,
|
||||
height: 10.0,
|
||||
width: 10.0,
|
||||
child: const ColoredBox(
|
||||
color: Colors.pink,
|
||||
),
|
||||
),
|
||||
itemBuilder: (BuildContext context) => <PopupMenuEntry<int>>[
|
||||
const PopupMenuItem<int>(child: Text('-1-'), value: 1,),
|
||||
const PopupMenuItem<int>(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 {
|
||||
|
||||
Reference in New Issue
Block a user