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
73996ea4
Unverified
Commit
73996ea4
authored
Apr 06, 2023
by
Henry Riehl
Committed by
GitHub
Apr 06, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add vertical alignment offset to the ```MenuAnchor``` widget when overflowing (#123740)
Positioning of cascading menus.
parent
8fdd2e08
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
1 deletion
+105
-1
menu_anchor.dart
packages/flutter/lib/src/material/menu_anchor.dart
+6
-1
menu_anchor_test.dart
packages/flutter/test/material/menu_anchor_test.dart
+99
-0
No files found.
packages/flutter/lib/src/material/menu_anchor.dart
View file @
73996ea4
...
...
@@ -3177,7 +3177,12 @@ class _MenuLayout extends SingleChildLayoutDelegate {
}
else
if
(
offBottom
(
y
))
{
final
double
newY
=
anchorRect
.
top
-
childSize
.
height
;
if
(!
offTop
(
newY
))
{
y
=
newY
;
// Only move the menu up if its parent is horizontal (MenuAchor/MenuBar).
if
(
parentOrientation
==
Axis
.
horizontal
)
{
y
=
newY
-
alignmentOffset
.
dy
;
}
else
{
y
=
newY
;
}
}
else
{
y
=
allowedRect
.
bottom
-
childSize
.
height
;
}
...
...
packages/flutter/test/material/menu_anchor_test.dart
View file @
73996ea4
...
...
@@ -2481,6 +2481,105 @@ void main() {
);
});
testWidgets
(
'vertically constrained menus are positioned above the anchor by default'
,
(
WidgetTester
tester
)
async
{
await
changeSurfaceSize
(
tester
,
const
Size
(
800
,
600
));
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Builder
(
builder:
(
BuildContext
context
)
{
return
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Align
(
alignment:
Alignment
.
bottomLeft
,
child:
MenuAnchor
(
menuChildren:
const
<
Widget
>
[
MenuItemButton
(
child:
Text
(
'Button1'
),
),
],
builder:
(
BuildContext
context
,
MenuController
controller
,
Widget
?
child
)
{
return
FilledButton
(
onPressed:
()
{
if
(
controller
.
isOpen
)
{
controller
.
close
();
}
else
{
controller
.
open
();
}
},
child:
const
Text
(
'Tap me'
),
);
},
),
),
);
},
),
),
);
await
tester
.
pump
();
await
tester
.
tap
(
find
.
text
(
'Tap me'
));
await
tester
.
pump
();
expect
(
find
.
byType
(
MenuItemButton
),
findsNWidgets
(
1
));
// Test the default offset (0, 0) vertical position.
expect
(
collectSubmenuRects
(),
equals
(
const
<
Rect
>[
Rect
.
fromLTRB
(
0.0
,
488.0
,
122.0
,
552.0
),
]),
);
});
testWidgets
(
'vertically constrained menus are positioned above the anchor with the provided offset'
,
(
WidgetTester
tester
)
async
{
await
changeSurfaceSize
(
tester
,
const
Size
(
800
,
600
));
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Builder
(
builder:
(
BuildContext
context
)
{
return
Directionality
(
textDirection:
TextDirection
.
ltr
,
child:
Align
(
alignment:
Alignment
.
bottomLeft
,
child:
MenuAnchor
(
alignmentOffset:
const
Offset
(
0
,
50
),
menuChildren:
const
<
Widget
>
[
MenuItemButton
(
child:
Text
(
'Button1'
),
),
],
builder:
(
BuildContext
context
,
MenuController
controller
,
Widget
?
child
)
{
return
FilledButton
(
onPressed:
()
{
if
(
controller
.
isOpen
)
{
controller
.
close
();
}
else
{
controller
.
open
();
}
},
child:
const
Text
(
'Tap me'
),
);
},
),
),
);
},
),
),
);
await
tester
.
pump
();
await
tester
.
tap
(
find
.
text
(
'Tap me'
));
await
tester
.
pump
();
expect
(
find
.
byType
(
MenuItemButton
),
findsNWidgets
(
1
));
// Test the offset (0, 50) vertical position.
expect
(
collectSubmenuRects
(),
equals
(
const
<
Rect
>[
Rect
.
fromLTRB
(
0.0
,
438.0
,
122.0
,
502.0
),
]),
);
});
Future
<
void
>
buildDensityPaddingApp
(
WidgetTester
tester
,
{
required
TextDirection
textDirection
,
VisualDensity
visualDensity
=
VisualDensity
.
standard
,
...
...
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