@@ -13,6 +13,7 @@ PopupMenuThemeData _popupMenuTheme() {
1313 shape: BeveledRectangleBorder (borderRadius: BorderRadius .all (Radius .circular (12 ))),
1414 elevation: 12.0 ,
1515 textStyle: TextStyle (color: Color (0xffffffff ), textBaseline: TextBaseline .alphabetic),
16+ position: PopupMenuPosition .under,
1617 );
1718}
1819
@@ -29,6 +30,7 @@ void main() {
2930 expect (popupMenuTheme.elevation, null );
3031 expect (popupMenuTheme.textStyle, null );
3132 expect (popupMenuTheme.mouseCursor, null );
33+ expect (popupMenuTheme.position, null );
3234 });
3335
3436 testWidgets ('Default PopupMenuThemeData debugFillProperties' , (WidgetTester tester) async {
@@ -51,6 +53,7 @@ void main() {
5153 elevation: 2.0 ,
5254 textStyle: TextStyle (color: Color (0xffffffff )),
5355 mouseCursor: MaterialStateMouseCursor .clickable,
56+ position: PopupMenuPosition .over,
5457 ).debugFillProperties (builder);
5558
5659 final List <String > description = builder.properties
@@ -64,6 +67,7 @@ void main() {
6467 'elevation: 2.0' ,
6568 'text style: TextStyle(inherit: true, color: Color(0xffffffff))' ,
6669 'mouseCursor: MaterialStateMouseCursor(clickable)' ,
70+ 'position: over'
6771 ]);
6872 });
6973
@@ -78,16 +82,21 @@ void main() {
7882 home: Material (
7983 child: Column (
8084 children: < Widget > [
81- PopupMenuButton <void >(
82- key: popupButtonKey,
83- itemBuilder: (BuildContext context) {
84- return < PopupMenuEntry <void >> [
85- PopupMenuItem <void >(
86- key: popupItemKey,
87- child: const Text ('Example' ),
88- ),
89- ];
90- },
85+ Padding (
86+ // The padding makes sure the menu as enough space to around to
87+ // get properly aligned when displayed (`_kMenuScreenPadding`).
88+ padding: const EdgeInsets .all (8.0 ),
89+ child: PopupMenuButton <void >(
90+ key: popupButtonKey,
91+ itemBuilder: (BuildContext context) {
92+ return < PopupMenuEntry <void >> [
93+ PopupMenuItem <void >(
94+ key: popupItemKey,
95+ child: const Text ('Example' ),
96+ ),
97+ ];
98+ },
99+ ),
91100 ),
92101 ],
93102 ),
@@ -123,6 +132,11 @@ void main() {
123132 );
124133 expect (text.style.fontFamily, 'Roboto' );
125134 expect (text.style.color, const Color (0xdd000000 ));
135+ expect (text.style.color, const Color (0xdd000000 ));
136+
137+ final Offset topLeftButton = tester.getTopLeft (find.byType (PopupMenuButton <void >));
138+ final Offset topLeftMenu = tester.getTopLeft (find.byWidget (button));
139+ expect (topLeftMenu, topLeftButton);
126140 });
127141
128142 testWidgets ('Popup menu uses values from PopupMenuThemeData' , (WidgetTester tester) async {
@@ -138,6 +152,10 @@ void main() {
138152 child: Column (
139153 children: < Widget > [
140154 PopupMenuButton <void >(
155+ // The padding is used in the positioning of the menu when the
156+ // position is `PopupMenuPosition.under`. Setting it to zero makes
157+ // it easier to test.
158+ padding: EdgeInsets .zero,
141159 key: popupButtonKey,
142160 itemBuilder: (BuildContext context) {
143161 return < PopupMenuEntry <Object >> [
@@ -181,6 +199,10 @@ void main() {
181199 ).last,
182200 );
183201 expect (text.style, popupMenuTheme.textStyle);
202+
203+ final Offset bottomLeftButton = tester.getBottomLeft (find.byType (PopupMenuButton <void >));
204+ final Offset topLeftMenu = tester.getTopLeft (find.byWidget (button));
205+ expect (topLeftMenu, bottomLeftButton);
184206 });
185207
186208 testWidgets ('Popup menu widget properties take priority over theme' , (WidgetTester tester) async {
@@ -202,20 +224,26 @@ void main() {
202224 home: Material (
203225 child: Column (
204226 children: < Widget > [
205- PopupMenuButton <void >(
206- key: popupButtonKey,
207- elevation: elevation,
208- color: color,
209- shape: shape,
210- itemBuilder: (BuildContext context) {
211- return < PopupMenuEntry <void >> [
212- PopupMenuItem <void >(
213- key: popupItemKey,
214- textStyle: textStyle,
215- child: const Text ('Example' ),
216- ),
217- ];
218- },
227+ Padding (
228+ // The padding makes sure the menu as enough space to around to
229+ // get properly aligned when displayed (`_kMenuScreenPadding`).
230+ padding: const EdgeInsets .all (8.0 ),
231+ child: PopupMenuButton <void >(
232+ key: popupButtonKey,
233+ elevation: elevation,
234+ color: color,
235+ shape: shape,
236+ position: PopupMenuPosition .over,
237+ itemBuilder: (BuildContext context) {
238+ return < PopupMenuEntry <void >> [
239+ PopupMenuItem <void >(
240+ key: popupItemKey,
241+ textStyle: textStyle,
242+ child: const Text ('Example' ),
243+ ),
244+ ];
245+ },
246+ ),
219247 ),
220248 ],
221249 ),
@@ -250,6 +278,10 @@ void main() {
250278 ).last,
251279 );
252280 expect (text.style, textStyle);
281+
282+ final Offset topLeftButton = tester.getTopLeft (find.byType (PopupMenuButton <void >));
283+ final Offset topLeftMenu = tester.getTopLeft (find.byWidget (button));
284+ expect (topLeftMenu, topLeftButton);
253285 });
254286
255287 testWidgets ('ThemeData.popupMenuTheme properties are utilized' , (WidgetTester tester) async {
0 commit comments