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
b378d967
Commit
b378d967
authored
Dec 16, 2015
by
Ian Hickson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #951 from Hixie/dropdown-cancel
Canceling a dropdown menu selects null value
parents
09ab8050
0c6e3416
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
7 deletions
+25
-7
dropdown.dart
packages/flutter/lib/src/material/dropdown.dart
+25
-7
No files found.
packages/flutter/lib/src/material/dropdown.dart
View file @
b378d967
...
...
@@ -95,7 +95,10 @@ class _DropDownMenu<T> extends StatusTransitionComponent {
padding:
_kMenuHorizontalPadding
,
child:
route
.
items
[
itemIndex
]
),
onTap:
()
=>
Navigator
.
pop
(
context
,
route
.
items
[
itemIndex
].
value
)
onTap:
()
=>
Navigator
.
pop
(
context
,
new
_DropDownRouteResult
<
T
>(
route
.
items
[
itemIndex
].
value
)
)
)
));
}
...
...
@@ -143,9 +146,24 @@ class _DropDownMenu<T> extends StatusTransitionComponent {
}
}
class
_DropDownRoute
<
T
>
extends
PopupRoute
<
T
>
{
// We box the return value so that the return value can be null. Otherwise,
// canceling the route (which returns null) would get confused with actually
// returning a real null value.
class
_DropDownRouteResult
<
T
>
{
const
_DropDownRouteResult
(
this
.
result
);
final
T
result
;
bool
operator
==(
dynamic
other
)
{
if
(
other
is
!
_DropDownRouteResult
)
return
false
;
final
_DropDownRouteResult
<
T
>
typedOther
=
other
;
return
result
==
typedOther
.
result
;
}
int
get
hashCode
=>
result
.
hashCode
;
}
class
_DropDownRoute
<
T
>
extends
PopupRoute
<
_DropDownRouteResult
<
T
>>
{
_DropDownRoute
({
Completer
<
T
>
completer
,
Completer
<
_DropDownRouteResult
<
T
>
>
completer
,
this
.
items
,
this
.
selectedIndex
,
this
.
rect
,
...
...
@@ -246,7 +264,7 @@ class _DropDownButtonState<T> extends State<DropDownButton<T>> {
void
_handleTap
()
{
final
RenderBox
renderBox
=
indexedStackKey
.
currentContext
.
findRenderObject
();
final
Rect
rect
=
renderBox
.
localToGlobal
(
Point
.
origin
)
&
renderBox
.
size
;
final
Completer
completer
=
new
Completer
<
T
>();
final
Completer
completer
=
new
Completer
<
_DropDownRouteResult
<
T
>
>();
Navigator
.
push
(
context
,
new
_DropDownRoute
<
T
>(
completer:
completer
,
items:
config
.
items
,
...
...
@@ -254,11 +272,11 @@ class _DropDownButtonState<T> extends State<DropDownButton<T>> {
rect:
_kMenuHorizontalPadding
.
inflateRect
(
rect
),
elevation:
config
.
elevation
));
completer
.
future
.
then
((
T
newValue
)
{
if
(!
mounted
)
completer
.
future
.
then
((
_DropDownRouteResult
<
T
>
newValue
)
{
if
(!
mounted
||
newValue
==
null
)
return
;
if
(
config
.
onChanged
!=
null
)
config
.
onChanged
(
newValue
);
config
.
onChanged
(
newValue
.
result
);
});
}
...
...
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