Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
935185ac
Unverified
Commit
935185ac
authored
Nov 09, 2020
by
xubaolin
Committed by
GitHub
Nov 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the PopupMenuButton offset bug (#69383)
parent
879466ea
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
11 deletions
+31
-11
popup_menu.dart
packages/flutter/lib/src/material/popup_menu.dart
+1
-1
popup_menu_test.dart
packages/flutter/test/material/popup_menu_test.dart
+30
-10
No files found.
packages/flutter/lib/src/material/popup_menu.dart
View file @
935185ac
...
...
@@ -1053,7 +1053,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
final
RelativeRect
position
=
RelativeRect
.
fromRect
(
Rect
.
fromPoints
(
button
.
localToGlobal
(
widget
.
offset
,
ancestor:
overlay
),
button
.
localToGlobal
(
button
.
size
.
bottomRight
(
Offset
.
zero
),
ancestor:
overlay
),
button
.
localToGlobal
(
button
.
size
.
bottomRight
(
Offset
.
zero
)
+
widget
.
offset
,
ancestor:
overlay
),
),
Offset
.
zero
&
overlay
.
size
,
);
...
...
packages/flutter/test/material/popup_menu_test.dart
View file @
935185ac
...
...
@@ -759,10 +759,8 @@ void main() {
});
testWidgets
(
'Popup Menu Offset Test'
,
(
WidgetTester
tester
)
async
{
const
Offset
offset
=
Offset
(
100.0
,
100.0
);
final
PopupMenuButton
<
int
>
popupMenuButton
=
PopupMenuButton
<
int
>(
PopupMenuButton
<
int
>
buildMenuButton
({
Offset
offset
=
const
Offset
(
0.0
,
0.0
)})
{
return
PopupMenuButton
<
int
>(
offset:
offset
,
itemBuilder:
(
BuildContext
context
)
{
return
<
PopupMenuItem
<
int
>>[
...
...
@@ -777,14 +775,36 @@ void main() {
];
},
);
}
// Popup a menu without any offset.
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
Material
(
child:
popupMenuButton
,
),
body:
Material
(
child:
buildMenuButton
(),
),
),
),
);
// Popup the menu.
await
tester
.
tap
(
find
.
byType
(
IconButton
));
await
tester
.
pumpAndSettle
();
// Initial state, the menu start at Offset(8.0, 8.0), the 8 pixels is edge padding when offset.dx < 8.0.
expect
(
tester
.
getTopLeft
(
find
.
byWidgetPredicate
((
Widget
w
)
=>
'
${w.runtimeType}
'
==
'_PopupMenu<int?>'
)),
const
Offset
(
8.0
,
8.0
));
// Collapse the menu.
await
tester
.
tap
(
find
.
byType
(
IconButton
));
await
tester
.
pumpAndSettle
();
// Popup a new menu with Offset(50.0, 50.0).
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Material
(
child:
buildMenuButton
(
offset:
const
Offset
(
50.0
,
50.0
)),
),
),
),
...
...
@@ -793,8 +813,8 @@ void main() {
await
tester
.
tap
(
find
.
byType
(
IconButton
));
await
tester
.
pumpAndSettle
();
// Th
e position is different than the offset because the default position isn't at the origin
.
expect
(
tester
.
getTopLeft
(
find
.
byWidgetPredicate
((
Widget
w
)
=>
'
${w.runtimeType}
'
==
'_PopupMenu<int?>'
)),
const
Offset
(
364.0
,
324
.0
));
// Th
is time the menu should start at Offset(50.0, 50.0), the padding only added when offset.dx < 8.0
.
expect
(
tester
.
getTopLeft
(
find
.
byWidgetPredicate
((
Widget
w
)
=>
'
${w.runtimeType}
'
==
'_PopupMenu<int?>'
)),
const
Offset
(
50.0
,
50
.0
));
});
testWidgets
(
'open PopupMenu has correct semantics'
,
(
WidgetTester
tester
)
async
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment