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
db5434e5
Unverified
Commit
db5434e5
authored
Mar 31, 2023
by
Qun Cheng
Committed by
GitHub
Mar 31, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix menu width issue for `DropdownMenu` (#123823)
parent
e6c2abb0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
2 deletions
+55
-2
dropdown_menu.dart
packages/flutter/lib/src/material/dropdown_menu.dart
+3
-2
dropdown_menu_test.dart
packages/flutter/test/material/dropdown_menu_test.dart
+52
-0
No files found.
packages/flutter/lib/src/material/dropdown_menu.dart
View file @
db5434e5
...
@@ -19,6 +19,7 @@ import 'menu_anchor.dart';
...
@@ -19,6 +19,7 @@ import 'menu_anchor.dart';
import
'menu_style.dart'
;
import
'menu_style.dart'
;
import
'text_field.dart'
;
import
'text_field.dart'
;
import
'theme.dart'
;
import
'theme.dart'
;
import
'theme_data.dart'
;
// Navigation shortcuts to move the selected menu items up or down.
// Navigation shortcuts to move the selected menu items up or down.
...
@@ -535,10 +536,10 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
...
@@ -535,10 +536,10 @@ class _DropdownMenuState<T> extends State<DropdownMenu<T>> {
);
);
return
_DropdownMenuBody
(
return
_DropdownMenuBody
(
key:
_anchorKey
,
width:
widget
.
width
,
width:
widget
.
width
,
children:
<
Widget
>[
children:
<
Widget
>[
TextField
(
TextField
(
key:
_anchorKey
,
mouseCursor:
effectiveMouseCursor
,
mouseCursor:
effectiveMouseCursor
,
canRequestFocus:
canRequestFocus
(),
canRequestFocus:
canRequestFocus
(),
enableInteractiveSelection:
canRequestFocus
(),
enableInteractiveSelection:
canRequestFocus
(),
...
@@ -607,7 +608,6 @@ class _ArrowDownIntent extends Intent {
...
@@ -607,7 +608,6 @@ class _ArrowDownIntent extends Intent {
class
_DropdownMenuBody
extends
MultiChildRenderObjectWidget
{
class
_DropdownMenuBody
extends
MultiChildRenderObjectWidget
{
const
_DropdownMenuBody
({
const
_DropdownMenuBody
({
super
.
key
,
super
.
children
,
super
.
children
,
this
.
width
,
this
.
width
,
});
});
...
@@ -826,6 +826,7 @@ class _DropdownMenuDefaultsM3 extends DropdownMenuThemeData {
...
@@ -826,6 +826,7 @@ class _DropdownMenuDefaultsM3 extends DropdownMenuThemeData {
return
const
MenuStyle
(
return
const
MenuStyle
(
minimumSize:
MaterialStatePropertyAll
<
Size
>(
Size
(
_kMinimumWidth
,
0.0
)),
minimumSize:
MaterialStatePropertyAll
<
Size
>(
Size
(
_kMinimumWidth
,
0.0
)),
maximumSize:
MaterialStatePropertyAll
<
Size
>(
Size
.
infinite
),
maximumSize:
MaterialStatePropertyAll
<
Size
>(
Size
.
infinite
),
visualDensity:
VisualDensity
.
standard
,
);
);
}
}
...
...
packages/flutter/test/material/dropdown_menu_test.dart
View file @
db5434e5
...
@@ -1058,6 +1058,58 @@ void main() {
...
@@ -1058,6 +1058,58 @@ void main() {
await
gesture
.
moveTo
(
tester
.
getCenter
(
textFieldFinder
));
await
gesture
.
moveTo
(
tester
.
getCenter
(
textFieldFinder
));
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
click
);
expect
(
RendererBinding
.
instance
.
mouseTracker
.
debugDeviceActiveCursor
(
1
),
SystemMouseCursors
.
click
);
});
});
testWidgets
(
'The menu has the same width as the input field in ListView'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/123631
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
ListView
(
children:
<
Widget
>[
DropdownMenu
<
TestMenu
>(
dropdownMenuEntries:
menuChildren
,
),
],
),
),
));
final
Rect
textInput
=
tester
.
getRect
(
find
.
byType
(
TextField
));
await
tester
.
tap
(
find
.
byType
(
TextField
));
await
tester
.
pumpAndSettle
();
final
Finder
findMenu
=
find
.
byWidgetPredicate
((
Widget
widget
)
{
return
widget
.
runtimeType
.
toString
()
==
'_MenuPanel'
;
});
final
Rect
menu
=
tester
.
getRect
(
findMenu
);
expect
(
textInput
.
width
,
menu
.
width
);
await
tester
.
pumpWidget
(
Container
());
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Scaffold
(
body:
ListView
(
children:
<
Widget
>[
DropdownMenu
<
TestMenu
>(
width:
200
,
dropdownMenuEntries:
menuChildren
,
),
],
),
),
));
final
Rect
textInput1
=
tester
.
getRect
(
find
.
byType
(
TextField
));
await
tester
.
tap
(
find
.
byType
(
TextField
));
await
tester
.
pumpAndSettle
();
final
Finder
findMenu1
=
find
.
byWidgetPredicate
((
Widget
widget
)
{
return
widget
.
runtimeType
.
toString
()
==
'_MenuPanel'
;
});
final
Rect
menu1
=
tester
.
getRect
(
findMenu1
);
expect
(
textInput1
.
width
,
200
);
expect
(
menu1
.
width
,
200
);
});
}
}
enum
TestMenu
{
enum
TestMenu
{
...
...
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