diff --git a/packages/flutter/lib/src/material/button_style.dart b/packages/flutter/lib/src/material/button_style.dart index 216c5c788d..51736adb22 100644 --- a/packages/flutter/lib/src/material/button_style.dart +++ b/packages/flutter/lib/src/material/button_style.dart @@ -132,6 +132,7 @@ class ButtonStyle with Diagnosticable { this.minimumSize, this.fixedSize, this.maximumSize, + this.iconSize, this.side, this.shape, this.mouseCursor, @@ -210,6 +211,9 @@ class ButtonStyle with Diagnosticable { /// This value must be greater than or equal to [minimumSize]. final MaterialStateProperty? maximumSize; + /// The icon's size inside of the button. + final MaterialStateProperty? iconSize; + /// The color and weight of the button's outline. /// /// This value is combined with [shape] to create a shape decorated @@ -300,6 +304,7 @@ class ButtonStyle with Diagnosticable { MaterialStateProperty? minimumSize, MaterialStateProperty? fixedSize, MaterialStateProperty? maximumSize, + MaterialStateProperty? iconSize, MaterialStateProperty? side, MaterialStateProperty? shape, MaterialStateProperty? mouseCursor, @@ -322,6 +327,7 @@ class ButtonStyle with Diagnosticable { minimumSize: minimumSize ?? this.minimumSize, fixedSize: fixedSize ?? this.fixedSize, maximumSize: maximumSize ?? this.maximumSize, + iconSize: iconSize ?? this.iconSize, side: side ?? this.side, shape: shape ?? this.shape, mouseCursor: mouseCursor ?? this.mouseCursor, @@ -355,6 +361,7 @@ class ButtonStyle with Diagnosticable { minimumSize: minimumSize ?? style.minimumSize, fixedSize: fixedSize ?? style.fixedSize, maximumSize: maximumSize ?? style.maximumSize, + iconSize: iconSize ?? style.iconSize, side: side ?? style.side, shape: shape ?? style.shape, mouseCursor: mouseCursor ?? style.mouseCursor, @@ -368,28 +375,32 @@ class ButtonStyle with Diagnosticable { } @override - int get hashCode => Object.hash( - textStyle, - backgroundColor, - foregroundColor, - overlayColor, - shadowColor, - surfaceTintColor, - elevation, - padding, - minimumSize, - fixedSize, - maximumSize, - side, - shape, - mouseCursor, - visualDensity, - tapTargetSize, - animationDuration, - enableFeedback, - alignment, - splashFactory, - ); + int get hashCode { + final List values = [ + textStyle, + backgroundColor, + foregroundColor, + overlayColor, + shadowColor, + surfaceTintColor, + elevation, + padding, + minimumSize, + fixedSize, + maximumSize, + iconSize, + side, + shape, + mouseCursor, + visualDensity, + tapTargetSize, + animationDuration, + enableFeedback, + alignment, + splashFactory, + ]; + return Object.hashAll(values); + } @override bool operator ==(Object other) { @@ -411,6 +422,7 @@ class ButtonStyle with Diagnosticable { && other.minimumSize == minimumSize && other.fixedSize == fixedSize && other.maximumSize == maximumSize + && other.iconSize == iconSize && other.side == side && other.shape == shape && other.mouseCursor == mouseCursor @@ -436,6 +448,7 @@ class ButtonStyle with Diagnosticable { properties.add(DiagnosticsProperty>('minimumSize', minimumSize, defaultValue: null)); properties.add(DiagnosticsProperty>('fixedSize', fixedSize, defaultValue: null)); properties.add(DiagnosticsProperty>('maximumSize', maximumSize, defaultValue: null)); + properties.add(DiagnosticsProperty>('iconSize', iconSize, defaultValue: null)); properties.add(DiagnosticsProperty>('side', side, defaultValue: null)); properties.add(DiagnosticsProperty>('shape', shape, defaultValue: null)); properties.add(DiagnosticsProperty>('mouseCursor', mouseCursor, defaultValue: null)); @@ -464,6 +477,7 @@ class ButtonStyle with Diagnosticable { minimumSize: _lerpProperties(a?.minimumSize, b?.minimumSize, t, Size.lerp), fixedSize: _lerpProperties(a?.fixedSize, b?.fixedSize, t, Size.lerp), maximumSize: _lerpProperties(a?.maximumSize, b?.maximumSize, t, Size.lerp), + iconSize: _lerpProperties(a?.iconSize, b?.iconSize, t, lerpDouble), side: _lerpSides(a?.side, b?.side, t), shape: MaterialStateProperty.lerp(a?.shape, b?.shape, t, OutlinedBorder.lerp), mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor, diff --git a/packages/flutter/lib/src/material/button_style_button.dart b/packages/flutter/lib/src/material/button_style_button.dart index 3a22b198d0..3dd671beb3 100644 --- a/packages/flutter/lib/src/material/button_style_button.dart +++ b/packages/flutter/lib/src/material/button_style_button.dart @@ -281,6 +281,7 @@ class _ButtonStyleState extends State with TickerProviderStat final Size? resolvedMinimumSize = resolve((ButtonStyle? style) => style?.minimumSize); final Size? resolvedFixedSize = resolve((ButtonStyle? style) => style?.fixedSize); final Size? resolvedMaximumSize = resolve((ButtonStyle? style) => style?.maximumSize); + final double? resolvedIconSize = resolve((ButtonStyle? style) => style?.iconSize); final BorderSide? resolvedSide = resolve((ButtonStyle? style) => style?.side); final OutlinedBorder? resolvedShape = resolve((ButtonStyle? style) => style?.shape); @@ -393,7 +394,7 @@ class _ButtonStyleState extends State with TickerProviderStat customBorder: resolvedShape.copyWith(side: resolvedSide), statesController: statesController, child: IconTheme.merge( - data: IconThemeData(color: resolvedForegroundColor), + data: IconThemeData(color: resolvedForegroundColor, size: resolvedIconSize), child: Padding( padding: padding, child: Align( diff --git a/packages/flutter/test/material/button_style_test.dart b/packages/flutter/test/material/button_style_test.dart index 0bd0baa6f8..11de84c7b5 100644 --- a/packages/flutter/test/material/button_style_test.dart +++ b/packages/flutter/test/material/button_style_test.dart @@ -27,6 +27,7 @@ void main() { expect(style.minimumSize, null); expect(style.fixedSize, null); expect(style.maximumSize, null); + expect(style.iconSize, null); expect(style.side, null); expect(style.shape, null); expect(style.mouseCursor, null); @@ -62,6 +63,7 @@ void main() { minimumSize: MaterialStatePropertyAll(Size(1.0, 2.0)), side: MaterialStatePropertyAll(BorderSide(width: 4.0, color: Color(0xfffffff6))), maximumSize: MaterialStatePropertyAll(Size(100.0, 200.0)), + iconSize: MaterialStatePropertyAll(48.1), shape: MaterialStatePropertyAll(StadiumBorder()), mouseCursor: MaterialStatePropertyAll(SystemMouseCursors.forbidden), tapTargetSize: MaterialTapTargetSize.shrinkWrap, @@ -85,6 +87,7 @@ void main() { 'padding: MaterialStatePropertyAll(EdgeInsets.all(1.0))', 'minimumSize: MaterialStatePropertyAll(Size(1.0, 2.0))', 'maximumSize: MaterialStatePropertyAll(Size(100.0, 200.0))', + 'iconSize: MaterialStatePropertyAll(48.1)', 'side: MaterialStatePropertyAll(BorderSide(Color(0xfffffff6), 4.0, BorderStyle.solid))', 'shape: MaterialStatePropertyAll(StadiumBorder(BorderSide(Color(0xff000000), 0.0, BorderStyle.none)))', 'mouseCursor: MaterialStatePropertyAll(SystemMouseCursor(forbidden))', @@ -106,6 +109,7 @@ void main() { const MaterialStateProperty minimumSize = MaterialStatePropertyAll(Size(1, 2)); const MaterialStateProperty fixedSize = MaterialStatePropertyAll(Size(3, 4)); const MaterialStateProperty maximumSize = MaterialStatePropertyAll(Size(5, 6)); + const MaterialStateProperty iconSize = MaterialStatePropertyAll(48.0); const MaterialStateProperty side = MaterialStatePropertyAll(BorderSide()); const MaterialStateProperty shape = MaterialStatePropertyAll(StadiumBorder()); const MaterialStateProperty mouseCursor = MaterialStatePropertyAll(SystemMouseCursors.forbidden); @@ -126,6 +130,7 @@ void main() { minimumSize: minimumSize, fixedSize: fixedSize, maximumSize: maximumSize, + iconSize: iconSize, side: side, shape: shape, mouseCursor: mouseCursor, @@ -149,6 +154,7 @@ void main() { minimumSize: minimumSize, fixedSize: fixedSize, maximumSize: maximumSize, + iconSize: iconSize, side: side, shape: shape, mouseCursor: mouseCursor,