@@ -573,9 +573,15 @@ class IconButton extends StatelessWidget {
573
573
/// [ButtonStyle.foregroundColor] value. Specify a value for [foregroundColor]
574
574
/// to specify the color of the button's icons. The [hoverColor] , [focusColor]
575
575
/// and [highlightColor] colors are used to indicate the hover, focus,
576
- /// and pressed states. Use [backgroundColor] for the button's background
577
- /// fill color. Use [disabledForegroundColor] and [disabledBackgroundColor]
578
- /// to specify the button's disabled icon and fill color.
576
+ /// and pressed states if [overlayColor] isn't specified.
577
+ ///
578
+ /// If [overlayColor] is specified and its value is [Colors.transparent]
579
+ /// then the pressed/focused/hovered highlights are effectively defeated.
580
+ /// Otherwise a [MaterialStateProperty] with the same opacities as the
581
+ /// default is created.
582
+ ///
583
+ /// Use [backgroundColor] for the button's background fill color. Use [disabledForegroundColor]
584
+ /// and [disabledBackgroundColor] to specify the button's disabled icon and fill color.
579
585
///
580
586
/// Similarly, the [enabledMouseCursor] and [disabledMouseCursor]
581
587
/// parameters are used to construct [ButtonStyle] .mouseCursor.
@@ -611,6 +617,7 @@ class IconButton extends StatelessWidget {
611
617
Color ? highlightColor,
612
618
Color ? shadowColor,
613
619
Color ? surfaceTintColor,
620
+ Color ? overlayColor,
614
621
double ? elevation,
615
622
Size ? minimumSize,
616
623
Size ? fixedSize,
@@ -629,20 +636,24 @@ class IconButton extends StatelessWidget {
629
636
InteractiveInkFeatureFactory ? splashFactory,
630
637
}) {
631
638
final MaterialStateProperty <Color ?>? buttonBackgroundColor = (backgroundColor == null && disabledBackgroundColor == null )
632
- ? null
633
- : _IconButtonDefaultBackground (backgroundColor, disabledBackgroundColor);
639
+ ? null
640
+ : _IconButtonDefaultBackground (backgroundColor, disabledBackgroundColor);
634
641
final MaterialStateProperty <Color ?>? buttonForegroundColor = (foregroundColor == null && disabledForegroundColor == null )
642
+ ? null
643
+ : _IconButtonDefaultForeground (foregroundColor, disabledForegroundColor);
644
+ final MaterialStateProperty <Color ?>? overlayColorProp = (foregroundColor == null &&
645
+ hoverColor == null && focusColor == null && highlightColor == null && overlayColor == null )
635
646
? null
636
- : _IconButtonDefaultForeground (foregroundColor, disabledForegroundColor);
637
- final MaterialStateProperty < Color ?> ? overlayColor = (foregroundColor == null && hoverColor == null && focusColor == null && highlightColor == null )
638
- ? null
639
- : _IconButtonDefaultOverlay (foregroundColor, focusColor, hoverColor, highlightColor) ;
647
+ : switch (overlayColor) {
648
+ ( final Color overlayColor) when overlayColor.value == 0 => const MaterialStatePropertyAll < Color ?>( Colors .transparent),
649
+ _ => _IconButtonDefaultOverlay (foregroundColor, focusColor, hoverColor, highlightColor, overlayColor),
650
+ } ;
640
651
final MaterialStateProperty <MouseCursor ?> mouseCursor = _IconButtonDefaultMouseCursor (enabledMouseCursor, disabledMouseCursor);
641
652
642
653
return ButtonStyle (
643
654
backgroundColor: buttonBackgroundColor,
644
655
foregroundColor: buttonForegroundColor,
645
- overlayColor: overlayColor ,
656
+ overlayColor: overlayColorProp ,
646
657
shadowColor: ButtonStyleButton .allOrNull <Color >(shadowColor),
647
658
surfaceTintColor: ButtonStyleButton .allOrNull <Color >(surfaceTintColor),
648
659
elevation: ButtonStyleButton .allOrNull <double >(elevation),
@@ -1023,34 +1034,41 @@ class _IconButtonDefaultForeground extends MaterialStateProperty<Color?> {
1023
1034
1024
1035
@immutable
1025
1036
class _IconButtonDefaultOverlay extends MaterialStateProperty <Color ?> {
1026
- _IconButtonDefaultOverlay (this .foregroundColor, this .focusColor, this .hoverColor, this .highlightColor);
1037
+ _IconButtonDefaultOverlay (
1038
+ this .foregroundColor,
1039
+ this .focusColor,
1040
+ this .hoverColor,
1041
+ this .highlightColor,
1042
+ this .overlayColor,
1043
+ );
1027
1044
1028
1045
final Color ? foregroundColor;
1029
1046
final Color ? focusColor;
1030
1047
final Color ? hoverColor;
1031
1048
final Color ? highlightColor;
1049
+ final Color ? overlayColor;
1032
1050
1033
1051
@override
1034
1052
Color ? resolve (Set <MaterialState > states) {
1035
1053
if (states.contains (MaterialState .selected)) {
1036
1054
if (states.contains (MaterialState .pressed)) {
1037
- return highlightColor ?? foregroundColor? .withOpacity (0.1 );
1055
+ return highlightColor ?? (overlayColor ?? foregroundColor) ? .withOpacity (0.1 );
1038
1056
}
1039
1057
if (states.contains (MaterialState .hovered)) {
1040
- return hoverColor ?? foregroundColor? .withOpacity (0.08 );
1058
+ return hoverColor ?? (overlayColor ?? foregroundColor) ? .withOpacity (0.08 );
1041
1059
}
1042
1060
if (states.contains (MaterialState .focused)) {
1043
- return focusColor ?? foregroundColor? .withOpacity (0.1 );
1061
+ return focusColor ?? (overlayColor ?? foregroundColor) ? .withOpacity (0.1 );
1044
1062
}
1045
1063
}
1046
1064
if (states.contains (MaterialState .pressed)) {
1047
- return highlightColor ?? foregroundColor? .withOpacity (0.1 );
1065
+ return highlightColor ?? (overlayColor ?? foregroundColor) ? .withOpacity (0.1 );
1048
1066
}
1049
1067
if (states.contains (MaterialState .hovered)) {
1050
- return hoverColor ?? foregroundColor? .withOpacity (0.08 );
1068
+ return hoverColor ?? (overlayColor ?? foregroundColor) ? .withOpacity (0.08 );
1051
1069
}
1052
1070
if (states.contains (MaterialState .focused)) {
1053
- return focusColor ?? foregroundColor? .withOpacity (0.1 );
1071
+ return focusColor ?? (overlayColor ?? foregroundColor) ? .withOpacity (0.1 );
1054
1072
}
1055
1073
return null ;
1056
1074
}
0 commit comments