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
6dc3bfaa
Unverified
Commit
6dc3bfaa
authored
Feb 08, 2020
by
Shi-Hao Hong
Committed by
GitHub
Feb 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Dropdown `'itemHeights' was called on null` crash (#50366)
parent
95d6ef74
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
1 deletion
+68
-1
dropdown.dart
packages/flutter/lib/src/material/dropdown.dart
+12
-1
dropdown_test.dart
packages/flutter/test/material/dropdown_test.dart
+56
-0
No files found.
packages/flutter/lib/src/material/dropdown.dart
View file @
6dc3bfaa
...
...
@@ -1143,6 +1143,17 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
menuItems
[
index
]
=
_MenuItem
<
T
>(
item:
widget
.
items
[
index
],
onLayout:
(
Size
size
)
{
// If [_dropdownRoute] is null and onLayout is called, this means
// that performLayout was called on a _DropdownRoute that has not
// left the widget tree but is already on its way out.
//
// Since onLayout is used primarily to collect the desired heights
// of each menu item before laying them out, not having the _DropdownRoute
// collect each item's height to lay out is fine since the route is
// already on its way out.
if
(
_dropdownRoute
==
null
)
return
;
_dropdownRoute
.
itemHeights
[
index
]
=
size
.
height
;
},
);
...
...
@@ -1162,7 +1173,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
);
Navigator
.
push
(
context
,
_dropdownRoute
).
then
<
void
>((
_DropdownRouteResult
<
T
>
newValue
)
{
_
dropdownRoute
=
null
;
_
removeDropdownRoute
()
;
if
(!
mounted
||
newValue
==
null
)
return
;
if
(
widget
.
onChanged
!=
null
)
...
...
packages/flutter/test/material/dropdown_test.dart
View file @
6dc3bfaa
...
...
@@ -1915,6 +1915,62 @@ void main() {
expect
(
tester
.
getCenter
(
item40
.
first
).
dy
,
tester
.
getCenter
(
item40
.
last
).
dy
);
});
testWidgets
(
'DropdownButton menu items do not resize when its route is popped'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/44877.
const
List
<
String
>
items
=
<
String
>[
'one'
,
'two'
,
'three'
,
];
String
item
=
items
[
0
];
MediaQueryData
mediaQuery
;
await
tester
.
pumpWidget
(
StatefulBuilder
(
builder:
(
BuildContext
context
,
StateSetter
setState
)
{
return
MaterialApp
(
builder:
(
BuildContext
context
,
Widget
child
)
{
mediaQuery
??=
MediaQuery
.
of
(
context
);
return
MediaQuery
(
data:
mediaQuery
,
child:
child
,
);
},
home:
Scaffold
(
body:
DropdownButton
<
String
>(
value:
item
,
items:
items
.
map
((
String
item
)
=>
DropdownMenuItem
<
String
>(
value:
item
,
child:
Text
(
item
),
)).
toList
(),
onChanged:
(
String
newItem
)
{
setState
(()
{
item
=
newItem
;
mediaQuery
=
mediaQuery
.
copyWith
(
textScaleFactor:
mediaQuery
.
textScaleFactor
+
0.1
,
);
});
},
),
),
);
},
),
);
// Verify that the first item is showing.
expect
(
find
.
text
(
'one'
),
findsOneWidget
);
// Select a different item to trigger setState, which updates mediaQuery
// and forces a performLayout on the popped _DropdownRoute. This operation
// should not cause an exception.
await
tester
.
tap
(
find
.
text
(
'one'
));
await
tester
.
pumpAndSettle
();
await
tester
.
tap
(
find
.
text
(
'two'
).
last
);
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'two'
),
findsOneWidget
);
});
testWidgets
(
'DropdownButton hint is selected item'
,
(
WidgetTester
tester
)
async
{
const
double
hintPaddingOffset
=
8
;
const
List
<
String
>
itemValues
=
<
String
>[
'item0'
,
'item1'
,
'item2'
,
'item3'
];
...
...
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