@@ -203,12 +203,14 @@ class _DropdownMenu<T> extends StatefulWidget {
203
203
this .route,
204
204
this .buttonRect,
205
205
this .constraints,
206
+ this .dropdownColor,
206
207
}) : super (key: key);
207
208
208
209
final _DropdownRoute <T > route;
209
210
final EdgeInsets padding;
210
211
final Rect buttonRect;
211
212
final BoxConstraints constraints;
213
+ final Color dropdownColor;
212
214
213
215
@override
214
216
_DropdownMenuState <T > createState () => _DropdownMenuState <T >();
@@ -265,7 +267,7 @@ class _DropdownMenuState<T> extends State<_DropdownMenu<T>> {
265
267
opacity: _fadeOpacity,
266
268
child: CustomPaint (
267
269
painter: _DropdownMenuPainter (
268
- color: Theme .of (context).canvasColor,
270
+ color: widget.dropdownColor ?? Theme .of (context).canvasColor,
269
271
elevation: route.elevation,
270
272
selectedIndex: route.selectedIndex,
271
273
resize: _resize,
@@ -400,6 +402,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
400
402
@required this .style,
401
403
this .barrierLabel,
402
404
this .itemHeight,
405
+ this .dropdownColor,
403
406
}) : assert (style != null ),
404
407
itemHeights = List <double >.filled (items.length, itemHeight ?? kMinInteractiveDimension);
405
408
@@ -411,6 +414,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
411
414
final ThemeData theme;
412
415
final TextStyle style;
413
416
final double itemHeight;
417
+ final Color dropdownColor;
414
418
415
419
final List <double > itemHeights;
416
420
ScrollController scrollController;
@@ -441,6 +445,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
441
445
elevation: elevation,
442
446
theme: theme,
443
447
style: style,
448
+ dropdownColor: dropdownColor,
444
449
);
445
450
}
446
451
);
@@ -526,6 +531,7 @@ class _DropdownRoutePage<T> extends StatelessWidget {
526
531
this .elevation = 8 ,
527
532
this .theme,
528
533
this .style,
534
+ this .dropdownColor,
529
535
}) : super (key: key);
530
536
531
537
final _DropdownRoute <T > route;
@@ -537,6 +543,7 @@ class _DropdownRoutePage<T> extends StatelessWidget {
537
543
final int elevation;
538
544
final ThemeData theme;
539
545
final TextStyle style;
546
+ final Color dropdownColor;
540
547
541
548
@override
542
549
Widget build (BuildContext context) {
@@ -559,6 +566,7 @@ class _DropdownRoutePage<T> extends StatelessWidget {
559
566
padding: padding.resolve (textDirection),
560
567
buttonRect: buttonRect,
561
568
constraints: constraints,
569
+ dropdownColor: dropdownColor,
562
570
);
563
571
564
572
if (theme != null )
@@ -789,6 +797,10 @@ class DropdownButton<T> extends StatefulWidget {
789
797
/// The [elevation] and [iconSize] arguments must not be null (they both have
790
798
/// defaults, so do not need to be specified). The boolean [isDense] and
791
799
/// [isExpanded] arguments must not be null.
800
+ ///
801
+ /// The [dropdownColor] argument specifies the background color of the
802
+ /// dropdown when it is open. If it is null, the current theme's
803
+ /// [ThemeData.canvasColor] will be used instead.
792
804
DropdownButton ({
793
805
Key key,
794
806
@required this .items,
@@ -811,6 +823,7 @@ class DropdownButton<T> extends StatefulWidget {
811
823
this .focusColor,
812
824
this .focusNode,
813
825
this .autofocus = false ,
826
+ this .dropdownColor,
814
827
}) : assert (items == null || items.isEmpty || value == null ||
815
828
items.where ((DropdownMenuItem <T > item) {
816
829
return item.value == value;
@@ -1049,6 +1062,12 @@ class DropdownButton<T> extends StatefulWidget {
1049
1062
/// {@macro flutter.widgets.Focus.autofocus}
1050
1063
final bool autofocus;
1051
1064
1065
+ /// The background color of the dropdown.
1066
+ ///
1067
+ /// If it is not provided, the theme's [ThemeData.canvasColor] will be used
1068
+ /// instead.
1069
+ final Color dropdownColor;
1070
+
1052
1071
@override
1053
1072
_DropdownButtonState <T > createState () => _DropdownButtonState <T >();
1054
1073
}
@@ -1189,6 +1208,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
1189
1208
style: _textStyle,
1190
1209
barrierLabel: MaterialLocalizations .of (context).modalBarrierDismissLabel,
1191
1210
itemHeight: widget.itemHeight,
1211
+ dropdownColor: widget.dropdownColor,
1192
1212
);
1193
1213
1194
1214
Navigator .push (context, _dropdownRoute).then <void >((_DropdownRouteResult <T > newValue) {
0 commit comments