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
ccaf5156
Unverified
Commit
ccaf5156
authored
Feb 15, 2022
by
Taha Tesser
Committed by
GitHub
Feb 15, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add custom size constraints parameter to `PopupMenu` (#97798)
parent
ff425fc7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
2 deletions
+63
-2
popup_menu.dart
packages/flutter/lib/src/material/popup_menu.dart
+30
-2
popup_menu_test.dart
packages/flutter/test/material/popup_menu_test.dart
+33
-0
No files found.
packages/flutter/lib/src/material/popup_menu.dart
View file @
ccaf5156
...
...
@@ -529,10 +529,12 @@ class _PopupMenu<T> extends StatelessWidget {
Key
?
key
,
required
this
.
route
,
required
this
.
semanticLabel
,
this
.
constraints
,
})
:
super
(
key:
key
);
final
_PopupMenuRoute
<
T
>
route
;
final
String
?
semanticLabel
;
final
BoxConstraints
?
constraints
;
@override
Widget
build
(
BuildContext
context
)
{
...
...
@@ -572,7 +574,7 @@ class _PopupMenu<T> extends StatelessWidget {
final
CurveTween
height
=
CurveTween
(
curve:
Interval
(
0.0
,
unit
*
route
.
items
.
length
));
final
Widget
child
=
ConstrainedBox
(
constraints:
const
BoxConstraints
(
constraints:
const
raints
??
const
BoxConstraints
(
minWidth:
_kMenuMinWidth
,
maxWidth:
_kMenuMaxWidth
,
),
...
...
@@ -735,6 +737,7 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
this
.
shape
,
this
.
color
,
required
this
.
capturedThemes
,
this
.
constraints
,
})
:
itemSizes
=
List
<
Size
?>.
filled
(
items
.
length
,
null
);
final
RelativeRect
position
;
...
...
@@ -746,6 +749,7 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
final
ShapeBorder
?
shape
;
final
Color
?
color
;
final
CapturedThemes
capturedThemes
;
final
BoxConstraints
?
constraints
;
@override
Animation
<
double
>
createAnimation
()
{
...
...
@@ -779,7 +783,11 @@ class _PopupMenuRoute<T> extends PopupRoute<T> {
}
}
final
Widget
menu
=
_PopupMenu
<
T
>(
route:
this
,
semanticLabel:
semanticLabel
);
final
Widget
menu
=
_PopupMenu
<
T
>(
route:
this
,
semanticLabel:
semanticLabel
,
constraints:
constraints
,
);
final
MediaQueryData
mediaQuery
=
MediaQuery
.
of
(
context
);
return
MediaQuery
.
removePadding
(
context:
context
,
...
...
@@ -870,6 +878,7 @@ Future<T?> showMenu<T>({
ShapeBorder
?
shape
,
Color
?
color
,
bool
useRootNavigator
=
false
,
BoxConstraints
?
constraints
,
})
{
assert
(
context
!=
null
);
assert
(
position
!=
null
);
...
...
@@ -899,6 +908,7 @@ Future<T?> showMenu<T>({
shape:
shape
,
color:
color
,
capturedThemes:
InheritedTheme
.
capture
(
from:
context
,
to:
navigator
.
context
),
constraints:
constraints
,
));
}
...
...
@@ -966,6 +976,7 @@ class PopupMenuButton<T> extends StatefulWidget {
this
.
shape
,
this
.
color
,
this
.
enableFeedback
,
this
.
constraints
,
})
:
assert
(
itemBuilder
!=
null
),
assert
(
offset
!=
null
),
assert
(
enabled
!=
null
),
...
...
@@ -1072,6 +1083,22 @@ class PopupMenuButton<T> extends StatefulWidget {
/// If this property is null, the default size is 24.0 pixels.
final
double
?
iconSize
;
/// Optional size constraints for the menu.
///
/// When unspecified, defaults to:
/// ```dart
/// const BoxConstraints(
/// minWidth: 2.0 * 56.0,
/// maxWidth: 5.0 * 56.0,
/// )
/// ```
///
/// The default constraints ensure that the menu width matches maximum width
/// recommended by the material design guidelines.
/// Specifying this parameter enables creation of menu wider than
/// the default maximum width.
final
BoxConstraints
?
constraints
;
@override
PopupMenuButtonState
<
T
>
createState
()
=>
PopupMenuButtonState
<
T
>();
}
...
...
@@ -1111,6 +1138,7 @@ class PopupMenuButtonState<T> extends State<PopupMenuButton<T>> {
position:
position
,
shape:
widget
.
shape
??
popupMenuTheme
.
shape
,
color:
widget
.
color
??
popupMenuTheme
.
color
,
constraints:
widget
.
constraints
,
)
.
then
<
void
>((
T
?
newValue
)
{
if
(!
mounted
)
...
...
packages/flutter/test/material/popup_menu_test.dart
View file @
ccaf5156
...
...
@@ -2536,6 +2536,39 @@ void main() {
expect
(
tester
.
widget
<
InkWell
>(
find
.
byType
(
InkWell
)).
radius
,
testSplashRadius
);
});
testWidgets
(
'Can override menu size constraints'
,
(
WidgetTester
tester
)
async
{
final
Key
popupMenuButtonKey
=
UniqueKey
();
final
Type
menuItemType
=
const
PopupMenuItem
<
String
>(
child:
Text
(
'item'
)).
runtimeType
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
Center
(
child:
PopupMenuButton
<
String
>(
key:
popupMenuButtonKey
,
constraints:
const
BoxConstraints
(
minWidth:
500
,
),
itemBuilder:
(
_
)
=>
<
PopupMenuEntry
<
String
>>[
const
PopupMenuItem
<
String
>(
value:
'value'
,
child:
Text
(
'Item 0'
),
),
],
),
),
),
),
);
// Show the menu
await
tester
.
tap
(
find
.
byKey
(
popupMenuButtonKey
));
await
tester
.
pumpAndSettle
();
expect
(
tester
.
getSize
(
find
.
widgetWithText
(
menuItemType
,
'Item 0'
)).
height
,
48
);
expect
(
tester
.
getSize
(
find
.
widgetWithText
(
menuItemType
,
'Item 0'
)).
width
,
500
);
});
}
class
TestApp
extends
StatefulWidget
{
...
...
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