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
5e54139a
Unverified
Commit
5e54139a
authored
Mar 15, 2023
by
Bruno Leroux
Committed by
GitHub
Mar 15, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix MenuAnchor closes on internal scroll (#122696)
Fix MenuAnchor closes on internal scroll
parent
67e5f663
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
4 deletions
+76
-4
menu_anchor.dart
packages/flutter/lib/src/material/menu_anchor.dart
+4
-4
menu_anchor_test.dart
packages/flutter/test/material/menu_anchor_test.dart
+72
-0
No files found.
packages/flutter/lib/src/material/menu_anchor.dart
View file @
5e54139a
...
...
@@ -463,10 +463,10 @@ class _MenuAnchorState extends State<MenuAnchor> {
}
void
_handleScroll
()
{
// If an ancestor scrolls, and we're a
top level or root anchor, then close
//
the menus. Don't just close it on *any* scroll, since we want to be able
//
to scroll
menus themselves if they're too big for the view.
if
(
_is
TopLevel
||
_is
Root
)
{
// If an ancestor scrolls, and we're a
root anchor, then close the menus.
//
Don't just close it on *any* scroll, since we want to be able to scroll
// menus themselves if they're too big for the view.
if
(
_isRoot
)
{
_root
.
_close
();
}
}
...
...
packages/flutter/test/material/menu_anchor_test.dart
View file @
5e54139a
...
...
@@ -1387,6 +1387,78 @@ void main() {
expect
(
closed
,
isNotEmpty
);
});
testWidgets
(
'menus do not close on root menu internal scroll'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/122168.
final
ScrollController
scrollController
=
ScrollController
();
bool
rootOpened
=
false
;
await
tester
.
pumpWidget
(
MaterialApp
(
theme:
ThemeData
(
menuButtonTheme:
MenuButtonThemeData
(
// Increase menu items height to make root menu scrollable.
style:
TextButton
.
styleFrom
(
minimumSize:
const
Size
.
fromHeight
(
200
)),
),
),
home:
Material
(
child:
SingleChildScrollView
(
controller:
scrollController
,
child:
Container
(
height:
1000
,
alignment:
Alignment
.
topLeft
,
child:
MenuAnchor
(
controller:
controller
,
alignmentOffset:
const
Offset
(
0
,
10
),
builder:
(
BuildContext
context
,
MenuController
controller
,
Widget
?
child
)
{
return
FilledButton
.
tonal
(
onPressed:
()
{
if
(
controller
.
isOpen
)
{
controller
.
close
();
}
else
{
controller
.
open
();
}
},
child:
const
Text
(
'Show menu'
),
);
},
onOpen:
()
{
rootOpened
=
true
;
},
onClose:
()
{
rootOpened
=
false
;
},
menuChildren:
createTestMenus
(
onPressed:
onPressed
,
onOpen:
onOpen
,
onClose:
onClose
,
includeExtraGroups:
true
,
),
),
),
),
),
),
);
await
tester
.
tap
(
find
.
text
(
'Show menu'
));
await
tester
.
pump
();
expect
(
rootOpened
,
true
);
// Hover the first item.
final
TestPointer
pointer
=
TestPointer
(
1
,
PointerDeviceKind
.
mouse
);
await
tester
.
sendEventToBinding
(
pointer
.
hover
(
tester
.
getCenter
(
find
.
text
(
TestMenu
.
mainMenu0
.
label
))));
await
tester
.
pump
();
expect
(
opened
,
isNotEmpty
);
// Menus do not close on internal scroll.
await
tester
.
sendEventToBinding
(
pointer
.
scroll
(
const
Offset
(
0.0
,
30.0
)));
await
tester
.
pump
();
expect
(
rootOpened
,
true
);
expect
(
closed
,
isEmpty
);
// Menus close on external scroll.
scrollController
.
jumpTo
(
1000
);
await
tester
.
pump
();
expect
(
rootOpened
,
false
);
expect
(
closed
,
isNotEmpty
);
});
testWidgets
(
'menus close on view size change'
,
(
WidgetTester
tester
)
async
{
final
ScrollController
scrollController
=
ScrollController
();
final
MediaQueryData
mediaQueryData
=
MediaQueryData
.
fromView
(
tester
.
view
);
...
...
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