@@ -330,15 +330,72 @@ public override Color barrierColor {
330
330
331
331
public override Widget buildPage ( BuildContext context , Animation < float > animation ,
332
332
Animation < float > secondaryAnimation ) {
333
+ return new LayoutBuilder (
334
+ builder : ( ctx , constraints ) => {
335
+ return new _DropdownRoutePage < T > (
336
+ route : this ,
337
+ constraints : constraints ,
338
+ items : this . items ,
339
+ padding : this . padding ,
340
+ buttonRect : this . buttonRect ,
341
+ selectedIndex : this . selectedIndex ,
342
+ elevation : this . elevation ,
343
+ theme : this . theme ,
344
+ style : this . style
345
+ ) ;
346
+ }
347
+ ) ;
348
+ }
349
+
350
+ internal void _dismiss ( ) {
351
+ this . navigator ? . removeRoute ( this ) ;
352
+ }
353
+ }
354
+
355
+ class _DropdownRoutePage < T > : StatelessWidget where T : class {
356
+ public _DropdownRoutePage (
357
+ Key key = null ,
358
+ _DropdownRoute < T > route = null ,
359
+ BoxConstraints constraints = null ,
360
+ List < DropdownMenuItem < T > > items = null ,
361
+ EdgeInsets padding = null ,
362
+ Rect buttonRect = null ,
363
+ int ? selectedIndex = null ,
364
+ int elevation = 0 ,
365
+ ThemeData theme = null ,
366
+ TextStyle style = null
367
+ ) : base ( key : key ) {
368
+ this . route = route ;
369
+ this . constraints = constraints ;
370
+ this . items = items ;
371
+ this . padding = padding ;
372
+ this . buttonRect = buttonRect ;
373
+ this . selectedIndex = selectedIndex ;
374
+ this . elevation = elevation ;
375
+ this . theme = theme ;
376
+ this . style = style ;
377
+ }
378
+
379
+ public readonly _DropdownRoute < T > route ;
380
+ public readonly BoxConstraints constraints ;
381
+ public readonly List < DropdownMenuItem < T > > items ;
382
+ public readonly EdgeInsets padding ;
383
+ public readonly Rect buttonRect ;
384
+ public readonly int ? selectedIndex ;
385
+ public readonly int elevation ;
386
+ public readonly ThemeData theme ;
387
+ public readonly TextStyle style ;
388
+
389
+ public override Widget build ( BuildContext context ) {
333
390
D . assert ( WidgetsD . debugCheckHasDirectionality ( context ) ) ;
334
- float screenHeight = MediaQuery . of ( context ) . size . height ;
335
- float maxMenuHeight = screenHeight - 2.0f * DropdownConstants . _kMenuItemHeight ;
391
+ float availableHeight = this . constraints . maxHeight ;
392
+ float maxMenuHeight = availableHeight - 2.0f * DropdownConstants . _kMenuItemHeight ;
336
393
337
394
float buttonTop = this . buttonRect . top ;
338
- float buttonBottom = this . buttonRect . bottom ;
395
+ float buttonBottom = Mathf . Min ( this . buttonRect . bottom , availableHeight ) ;
339
396
340
397
float topLimit = Mathf . Min ( DropdownConstants . _kMenuItemHeight , buttonTop ) ;
341
- float bottomLimit = Mathf . Max ( screenHeight - DropdownConstants . _kMenuItemHeight , buttonBottom ) ;
398
+ float bottomLimit = Mathf . Max ( availableHeight - DropdownConstants . _kMenuItemHeight , buttonBottom ) ;
342
399
343
400
float ? selectedItemOffset = this . selectedIndex * DropdownConstants . _kMenuItemHeight +
344
401
Constants . kMaterialListPadding . top ;
@@ -361,15 +418,15 @@ public override Widget buildPage(BuildContext context, Animation<float> animatio
361
418
menuTop = menuBottom - menuHeight ;
362
419
}
363
420
364
- if ( this . scrollController == null ) {
421
+ if ( this . route . scrollController == null ) {
365
422
float scrollOffset = preferredMenuHeight > maxMenuHeight
366
423
? Mathf . Max ( 0.0f , selectedItemOffset ?? 0.0f - ( buttonTop - ( menuTop ?? 0.0f ) ) )
367
424
: 0.0f ;
368
- this . scrollController = new ScrollController ( initialScrollOffset : scrollOffset ) ;
425
+ this . route . scrollController = new ScrollController ( initialScrollOffset : scrollOffset ) ;
369
426
}
370
427
371
428
Widget menu = new _DropdownMenu < T > (
372
- route : this ,
429
+ route : this . route ,
373
430
padding : this . padding
374
431
) ;
375
432
@@ -397,10 +454,6 @@ public override Widget buildPage(BuildContext context, Animation<float> animatio
397
454
)
398
455
) ;
399
456
}
400
-
401
- public void _dismiss ( ) {
402
- this . navigator ? . removeRoute ( this ) ;
403
- }
404
457
}
405
458
406
459
public class DropdownMenuItem < T > : StatelessWidget where T : class {
@@ -454,6 +507,10 @@ public DropdownButton(
454
507
ValueChanged < T > onChanged = null ,
455
508
int elevation = 8 ,
456
509
TextStyle style = null ,
510
+ Widget underline = null ,
511
+ Widget icon = null ,
512
+ Color iconDisabledColor = null ,
513
+ Color iconEnabledColor = null ,
457
514
float iconSize = 24.0f ,
458
515
bool isDense = false ,
459
516
bool isExpanded = false
@@ -469,6 +526,10 @@ public DropdownButton(
469
526
this . onChanged = onChanged ;
470
527
this . elevation = elevation ;
471
528
this . style = style ;
529
+ this . underline = underline ;
530
+ this . icon = icon ;
531
+ this . iconDisabledColor = iconDisabledColor ;
532
+ this . iconEnabledColor = iconEnabledColor ;
472
533
this . iconSize = iconSize ;
473
534
this . isDense = isDense ;
474
535
this . isExpanded = isExpanded ;
@@ -488,6 +549,14 @@ public DropdownButton(
488
549
489
550
public readonly TextStyle style ;
490
551
552
+ public readonly Widget underline ;
553
+
554
+ public readonly Widget icon ;
555
+
556
+ public readonly Color iconDisabledColor ;
557
+
558
+ public readonly Color iconEnabledColor ;
559
+
491
560
public readonly float iconSize ;
492
561
493
562
public readonly bool isDense ;
@@ -606,24 +675,34 @@ void _handleTap() {
606
675
}
607
676
}
608
677
609
- Color _downArrowColor {
678
+ Color _iconColor {
610
679
get {
611
680
if ( this . _enabled ) {
612
- if ( Theme . of ( this . context ) . brightness == Brightness . light ) {
613
- return Colors . grey . shade700 ;
681
+ if ( this . widget . iconEnabledColor != null ) {
682
+ return this . widget . iconEnabledColor ;
614
683
}
615
- else {
616
- return Colors . white70 ;
684
+
685
+ switch ( Theme . of ( this . context ) . brightness ) {
686
+ case Brightness . light :
687
+ return Colors . grey . shade700 ;
688
+ case Brightness . dark :
689
+ return Colors . white70 ;
617
690
}
618
691
}
619
692
else {
620
- if ( Theme . of ( this . context ) . brightness == Brightness . light ) {
621
- return Colors . grey . shade400 ;
693
+ if ( this . widget . iconDisabledColor != null ) {
694
+ return this . widget . iconDisabledColor ;
622
695
}
623
- else {
624
- return Colors . white10 ;
696
+
697
+ switch ( Theme . of ( this . context ) . brightness ) {
698
+ case Brightness . light :
699
+ return Colors . grey . shade400 ;
700
+ case Brightness . dark :
701
+ return Colors . white10 ;
625
702
}
626
703
}
704
+ D . assert ( false ) ;
705
+ return null ;
627
706
}
628
707
}
629
708
@@ -661,6 +740,7 @@ public override Widget build(BuildContext context) {
661
740
children : items
662
741
) ;
663
742
743
+ Icon defaultIcon = new Icon ( Icons . arrow_drop_down ) ;
664
744
Widget result = new DefaultTextStyle (
665
745
style : this . _textStyle ,
666
746
child : new Container (
@@ -671,9 +751,12 @@ public override Widget build(BuildContext context) {
671
751
mainAxisSize : MainAxisSize . min ,
672
752
children : new List < Widget > {
673
753
this . widget . isExpanded ? new Expanded ( child : innerItemsWidget ) : ( Widget ) innerItemsWidget ,
674
- new Icon ( Icons . arrow_drop_down ,
675
- size : this . widget . iconSize ,
676
- color : this . _downArrowColor
754
+ new IconTheme (
755
+ data : new IconThemeData (
756
+ color : this . _iconColor ,
757
+ size : this . widget . iconSize
758
+ ) ,
759
+ child : this . widget . icon ?? defaultIcon
677
760
)
678
761
}
679
762
)
@@ -689,7 +772,7 @@ public override Widget build(BuildContext context) {
689
772
left : 0.0f ,
690
773
right : 0.0f ,
691
774
bottom : bottom ,
692
- child : new Container (
775
+ child : this . widget . underline ?? new Container (
693
776
height : 1.0f ,
694
777
decoration : new BoxDecoration (
695
778
border : new Border (
0 commit comments