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
191f86ea
Unverified
Commit
191f86ea
authored
Apr 02, 2020
by
impure
Committed by
GitHub
Apr 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ability to change dropdown colour manually (#52982)
parent
54d75a51
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
1 deletion
+66
-1
dropdown.dart
packages/flutter/lib/src/material/dropdown.dart
+21
-1
dropdown_test.dart
packages/flutter/test/material/dropdown_test.dart
+45
-0
No files found.
packages/flutter/lib/src/material/dropdown.dart
View file @
191f86ea
...
@@ -203,12 +203,14 @@ class _DropdownMenu<T> extends StatefulWidget {
...
@@ -203,12 +203,14 @@ class _DropdownMenu<T> extends StatefulWidget {
this
.
route
,
this
.
route
,
this
.
buttonRect
,
this
.
buttonRect
,
this
.
constraints
,
this
.
constraints
,
this
.
dropdownColor
,
})
:
super
(
key:
key
);
})
:
super
(
key:
key
);
final
_DropdownRoute
<
T
>
route
;
final
_DropdownRoute
<
T
>
route
;
final
EdgeInsets
padding
;
final
EdgeInsets
padding
;
final
Rect
buttonRect
;
final
Rect
buttonRect
;
final
BoxConstraints
constraints
;
final
BoxConstraints
constraints
;
final
Color
dropdownColor
;
@override
@override
_DropdownMenuState
<
T
>
createState
()
=>
_DropdownMenuState
<
T
>();
_DropdownMenuState
<
T
>
createState
()
=>
_DropdownMenuState
<
T
>();
...
@@ -265,7 +267,7 @@ class _DropdownMenuState<T> extends State<_DropdownMenu<T>> {
...
@@ -265,7 +267,7 @@ class _DropdownMenuState<T> extends State<_DropdownMenu<T>> {
opacity:
_fadeOpacity
,
opacity:
_fadeOpacity
,
child:
CustomPaint
(
child:
CustomPaint
(
painter:
_DropdownMenuPainter
(
painter:
_DropdownMenuPainter
(
color:
Theme
.
of
(
context
).
canvasColor
,
color:
widget
.
dropdownColor
??
Theme
.
of
(
context
).
canvasColor
,
elevation:
route
.
elevation
,
elevation:
route
.
elevation
,
selectedIndex:
route
.
selectedIndex
,
selectedIndex:
route
.
selectedIndex
,
resize:
_resize
,
resize:
_resize
,
...
@@ -400,6 +402,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
...
@@ -400,6 +402,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
@required
this
.
style
,
@required
this
.
style
,
this
.
barrierLabel
,
this
.
barrierLabel
,
this
.
itemHeight
,
this
.
itemHeight
,
this
.
dropdownColor
,
})
:
assert
(
style
!=
null
),
})
:
assert
(
style
!=
null
),
itemHeights
=
List
<
double
>.
filled
(
items
.
length
,
itemHeight
??
kMinInteractiveDimension
);
itemHeights
=
List
<
double
>.
filled
(
items
.
length
,
itemHeight
??
kMinInteractiveDimension
);
...
@@ -411,6 +414,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
...
@@ -411,6 +414,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
final
ThemeData
theme
;
final
ThemeData
theme
;
final
TextStyle
style
;
final
TextStyle
style
;
final
double
itemHeight
;
final
double
itemHeight
;
final
Color
dropdownColor
;
final
List
<
double
>
itemHeights
;
final
List
<
double
>
itemHeights
;
ScrollController
scrollController
;
ScrollController
scrollController
;
...
@@ -441,6 +445,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
...
@@ -441,6 +445,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
elevation:
elevation
,
elevation:
elevation
,
theme:
theme
,
theme:
theme
,
style:
style
,
style:
style
,
dropdownColor:
dropdownColor
,
);
);
}
}
);
);
...
@@ -526,6 +531,7 @@ class _DropdownRoutePage<T> extends StatelessWidget {
...
@@ -526,6 +531,7 @@ class _DropdownRoutePage<T> extends StatelessWidget {
this
.
elevation
=
8
,
this
.
elevation
=
8
,
this
.
theme
,
this
.
theme
,
this
.
style
,
this
.
style
,
this
.
dropdownColor
,
})
:
super
(
key:
key
);
})
:
super
(
key:
key
);
final
_DropdownRoute
<
T
>
route
;
final
_DropdownRoute
<
T
>
route
;
...
@@ -537,6 +543,7 @@ class _DropdownRoutePage<T> extends StatelessWidget {
...
@@ -537,6 +543,7 @@ class _DropdownRoutePage<T> extends StatelessWidget {
final
int
elevation
;
final
int
elevation
;
final
ThemeData
theme
;
final
ThemeData
theme
;
final
TextStyle
style
;
final
TextStyle
style
;
final
Color
dropdownColor
;
@override
@override
Widget
build
(
BuildContext
context
)
{
Widget
build
(
BuildContext
context
)
{
...
@@ -559,6 +566,7 @@ class _DropdownRoutePage<T> extends StatelessWidget {
...
@@ -559,6 +566,7 @@ class _DropdownRoutePage<T> extends StatelessWidget {
padding:
padding
.
resolve
(
textDirection
),
padding:
padding
.
resolve
(
textDirection
),
buttonRect:
buttonRect
,
buttonRect:
buttonRect
,
constraints:
constraints
,
constraints:
constraints
,
dropdownColor:
dropdownColor
,
);
);
if
(
theme
!=
null
)
if
(
theme
!=
null
)
...
@@ -789,6 +797,10 @@ class DropdownButton<T> extends StatefulWidget {
...
@@ -789,6 +797,10 @@ class DropdownButton<T> extends StatefulWidget {
/// The [elevation] and [iconSize] arguments must not be null (they both have
/// The [elevation] and [iconSize] arguments must not be null (they both have
/// defaults, so do not need to be specified). The boolean [isDense] and
/// defaults, so do not need to be specified). The boolean [isDense] and
/// [isExpanded] arguments must not be null.
/// [isExpanded] arguments must not be null.
///
/// The [dropdownColor] argument specifies the background color of the
/// dropdown when it is open. If it is null, the current theme's
/// [ThemeData.canvasColor] will be used instead.
DropdownButton
({
DropdownButton
({
Key
key
,
Key
key
,
@required
this
.
items
,
@required
this
.
items
,
...
@@ -811,6 +823,7 @@ class DropdownButton<T> extends StatefulWidget {
...
@@ -811,6 +823,7 @@ class DropdownButton<T> extends StatefulWidget {
this
.
focusColor
,
this
.
focusColor
,
this
.
focusNode
,
this
.
focusNode
,
this
.
autofocus
=
false
,
this
.
autofocus
=
false
,
this
.
dropdownColor
,
})
:
assert
(
items
==
null
||
items
.
isEmpty
||
value
==
null
||
})
:
assert
(
items
==
null
||
items
.
isEmpty
||
value
==
null
||
items
.
where
((
DropdownMenuItem
<
T
>
item
)
{
items
.
where
((
DropdownMenuItem
<
T
>
item
)
{
return
item
.
value
==
value
;
return
item
.
value
==
value
;
...
@@ -1049,6 +1062,12 @@ class DropdownButton<T> extends StatefulWidget {
...
@@ -1049,6 +1062,12 @@ class DropdownButton<T> extends StatefulWidget {
/// {@macro flutter.widgets.Focus.autofocus}
/// {@macro flutter.widgets.Focus.autofocus}
final
bool
autofocus
;
final
bool
autofocus
;
/// The background color of the dropdown.
///
/// If it is not provided, the theme's [ThemeData.canvasColor] will be used
/// instead.
final
Color
dropdownColor
;
@override
@override
_DropdownButtonState
<
T
>
createState
()
=>
_DropdownButtonState
<
T
>();
_DropdownButtonState
<
T
>
createState
()
=>
_DropdownButtonState
<
T
>();
}
}
...
@@ -1189,6 +1208,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
...
@@ -1189,6 +1208,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
style:
_textStyle
,
style:
_textStyle
,
barrierLabel:
MaterialLocalizations
.
of
(
context
).
modalBarrierDismissLabel
,
barrierLabel:
MaterialLocalizations
.
of
(
context
).
modalBarrierDismissLabel
,
itemHeight:
widget
.
itemHeight
,
itemHeight:
widget
.
itemHeight
,
dropdownColor:
widget
.
dropdownColor
,
);
);
Navigator
.
push
(
context
,
_dropdownRoute
).
then
<
void
>((
_DropdownRouteResult
<
T
>
newValue
)
{
Navigator
.
push
(
context
,
_dropdownRoute
).
then
<
void
>((
_DropdownRouteResult
<
T
>
newValue
)
{
...
...
packages/flutter/test/material/dropdown_test.dart
View file @
191f86ea
...
@@ -53,6 +53,7 @@ Widget buildFrame({
...
@@ -53,6 +53,7 @@ Widget buildFrame({
FocusNode
focusNode
,
FocusNode
focusNode
,
bool
autofocus
=
false
,
bool
autofocus
=
false
,
Color
focusColor
,
Color
focusColor
,
Color
dropdownColor
,
})
{
})
{
return
TestApp
(
return
TestApp
(
textDirection:
textDirection
,
textDirection:
textDirection
,
...
@@ -78,6 +79,7 @@ Widget buildFrame({
...
@@ -78,6 +79,7 @@ Widget buildFrame({
focusNode:
focusNode
,
focusNode:
focusNode
,
autofocus:
autofocus
,
autofocus:
autofocus
,
focusColor:
focusColor
,
focusColor:
focusColor
,
dropdownColor:
dropdownColor
,
items:
items
==
null
?
null
:
items
.
map
<
DropdownMenuItem
<
String
>>((
String
item
)
{
items:
items
==
null
?
null
:
items
.
map
<
DropdownMenuItem
<
String
>>((
String
item
)
{
return
DropdownMenuItem
<
String
>(
return
DropdownMenuItem
<
String
>(
key:
ValueKey
<
String
>(
item
),
key:
ValueKey
<
String
>(
item
),
...
@@ -174,6 +176,41 @@ void verifyPaintedShadow(Finder customPaint, int elevation) {
...
@@ -174,6 +176,41 @@ void verifyPaintedShadow(Finder customPaint, int elevation) {
);
);
}
}
Future
<
void
>
checkDropdownColor
(
WidgetTester
tester
,
{
Color
color
})
async
{
const
String
text
=
'foo'
;
await
tester
.
pumpWidget
(
MaterialApp
(
home:
Material
(
child:
DropdownButton
<
String
>(
dropdownColor:
color
,
value:
text
,
items:
const
<
DropdownMenuItem
<
String
>>[
DropdownMenuItem
<
String
>(
value:
text
,
child:
Text
(
text
),
),
],
onChanged:
(
_
)
{
},
),
),
),
);
await
tester
.
tap
(
find
.
text
(
text
));
await
tester
.
pump
();
expect
(
find
.
ancestor
(
of:
find
.
text
(
text
).
last
,
matching:
find
.
byType
(
CustomPaint
)).
at
(
2
),
paints
..
save
()
..
rrect
()
..
rrect
()
..
rrect
()
..
rrect
(
color:
color
??
Colors
.
grey
[
50
],
hasMaskFilter:
false
)
);
}
bool
sameGeometry
(
RenderBox
box1
,
RenderBox
box2
)
{
bool
sameGeometry
(
RenderBox
box1
,
RenderBox
box2
)
{
expect
(
box1
.
localToGlobal
(
Offset
.
zero
),
equals
(
box2
.
localToGlobal
(
Offset
.
zero
)));
expect
(
box1
.
localToGlobal
(
Offset
.
zero
),
equals
(
box2
.
localToGlobal
(
Offset
.
zero
)));
expect
(
box1
.
size
.
height
,
equals
(
box2
.
size
.
height
));
expect
(
box1
.
size
.
height
,
equals
(
box2
.
size
.
height
));
...
@@ -1774,6 +1811,14 @@ void main() {
...
@@ -1774,6 +1811,14 @@ void main() {
expect
(
find
.
text
(
'Two as an Arabic numeral: 2'
),
findsOneWidget
);
expect
(
find
.
text
(
'Two as an Arabic numeral: 2'
),
findsOneWidget
);
});
});
testWidgets
(
'DropdownButton uses default color when expanded'
,
(
WidgetTester
tester
)
async
{
await
checkDropdownColor
(
tester
);
});
testWidgets
(
'DropdownButton uses dropdownColor when expanded when given'
,
(
WidgetTester
tester
)
async
{
await
checkDropdownColor
(
tester
,
color:
const
Color
.
fromRGBO
(
120
,
220
,
70
,
0.8
));
});
testWidgets
(
'DropdownButton hint displays properly when selectedItemBuilder is defined'
,
(
WidgetTester
tester
)
async
{
testWidgets
(
'DropdownButton hint displays properly when selectedItemBuilder is defined'
,
(
WidgetTester
tester
)
async
{
// Regression test for https://github.com/flutter/flutter/issues/42340
// Regression test for https://github.com/flutter/flutter/issues/42340
final
List
<
String
>
items
=
<
String
>[
'1'
,
'2'
,
'3'
];
final
List
<
String
>
items
=
<
String
>[
'1'
,
'2'
,
'3'
];
...
...
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