Unverified Commit 606954d1 authored by Qun Cheng's avatar Qun Cheng Committed by GitHub

Added iconSize parameter in ButtonStyle (#108268)

* Added iconSize parameter in ButtonStyle
Co-authored-by: 's avatarQun Cheng <quncheng@google.com>
parent 5f67b47e
...@@ -132,6 +132,7 @@ class ButtonStyle with Diagnosticable { ...@@ -132,6 +132,7 @@ class ButtonStyle with Diagnosticable {
this.minimumSize, this.minimumSize,
this.fixedSize, this.fixedSize,
this.maximumSize, this.maximumSize,
this.iconSize,
this.side, this.side,
this.shape, this.shape,
this.mouseCursor, this.mouseCursor,
...@@ -210,6 +211,9 @@ class ButtonStyle with Diagnosticable { ...@@ -210,6 +211,9 @@ class ButtonStyle with Diagnosticable {
/// This value must be greater than or equal to [minimumSize]. /// This value must be greater than or equal to [minimumSize].
final MaterialStateProperty<Size?>? maximumSize; final MaterialStateProperty<Size?>? maximumSize;
/// The icon's size inside of the button.
final MaterialStateProperty<double?>? iconSize;
/// The color and weight of the button's outline. /// The color and weight of the button's outline.
/// ///
/// This value is combined with [shape] to create a shape decorated /// This value is combined with [shape] to create a shape decorated
...@@ -300,6 +304,7 @@ class ButtonStyle with Diagnosticable { ...@@ -300,6 +304,7 @@ class ButtonStyle with Diagnosticable {
MaterialStateProperty<Size?>? minimumSize, MaterialStateProperty<Size?>? minimumSize,
MaterialStateProperty<Size?>? fixedSize, MaterialStateProperty<Size?>? fixedSize,
MaterialStateProperty<Size?>? maximumSize, MaterialStateProperty<Size?>? maximumSize,
MaterialStateProperty<double?>? iconSize,
MaterialStateProperty<BorderSide?>? side, MaterialStateProperty<BorderSide?>? side,
MaterialStateProperty<OutlinedBorder?>? shape, MaterialStateProperty<OutlinedBorder?>? shape,
MaterialStateProperty<MouseCursor?>? mouseCursor, MaterialStateProperty<MouseCursor?>? mouseCursor,
...@@ -322,6 +327,7 @@ class ButtonStyle with Diagnosticable { ...@@ -322,6 +327,7 @@ class ButtonStyle with Diagnosticable {
minimumSize: minimumSize ?? this.minimumSize, minimumSize: minimumSize ?? this.minimumSize,
fixedSize: fixedSize ?? this.fixedSize, fixedSize: fixedSize ?? this.fixedSize,
maximumSize: maximumSize ?? this.maximumSize, maximumSize: maximumSize ?? this.maximumSize,
iconSize: iconSize ?? this.iconSize,
side: side ?? this.side, side: side ?? this.side,
shape: shape ?? this.shape, shape: shape ?? this.shape,
mouseCursor: mouseCursor ?? this.mouseCursor, mouseCursor: mouseCursor ?? this.mouseCursor,
...@@ -355,6 +361,7 @@ class ButtonStyle with Diagnosticable { ...@@ -355,6 +361,7 @@ class ButtonStyle with Diagnosticable {
minimumSize: minimumSize ?? style.minimumSize, minimumSize: minimumSize ?? style.minimumSize,
fixedSize: fixedSize ?? style.fixedSize, fixedSize: fixedSize ?? style.fixedSize,
maximumSize: maximumSize ?? style.maximumSize, maximumSize: maximumSize ?? style.maximumSize,
iconSize: iconSize ?? style.iconSize,
side: side ?? style.side, side: side ?? style.side,
shape: shape ?? style.shape, shape: shape ?? style.shape,
mouseCursor: mouseCursor ?? style.mouseCursor, mouseCursor: mouseCursor ?? style.mouseCursor,
...@@ -368,7 +375,8 @@ class ButtonStyle with Diagnosticable { ...@@ -368,7 +375,8 @@ class ButtonStyle with Diagnosticable {
} }
@override @override
int get hashCode => Object.hash( int get hashCode {
final List<Object?> values = <Object?>[
textStyle, textStyle,
backgroundColor, backgroundColor,
foregroundColor, foregroundColor,
...@@ -380,6 +388,7 @@ class ButtonStyle with Diagnosticable { ...@@ -380,6 +388,7 @@ class ButtonStyle with Diagnosticable {
minimumSize, minimumSize,
fixedSize, fixedSize,
maximumSize, maximumSize,
iconSize,
side, side,
shape, shape,
mouseCursor, mouseCursor,
...@@ -389,7 +398,9 @@ class ButtonStyle with Diagnosticable { ...@@ -389,7 +398,9 @@ class ButtonStyle with Diagnosticable {
enableFeedback, enableFeedback,
alignment, alignment,
splashFactory, splashFactory,
); ];
return Object.hashAll(values);
}
@override @override
bool operator ==(Object other) { bool operator ==(Object other) {
...@@ -411,6 +422,7 @@ class ButtonStyle with Diagnosticable { ...@@ -411,6 +422,7 @@ class ButtonStyle with Diagnosticable {
&& other.minimumSize == minimumSize && other.minimumSize == minimumSize
&& other.fixedSize == fixedSize && other.fixedSize == fixedSize
&& other.maximumSize == maximumSize && other.maximumSize == maximumSize
&& other.iconSize == iconSize
&& other.side == side && other.side == side
&& other.shape == shape && other.shape == shape
&& other.mouseCursor == mouseCursor && other.mouseCursor == mouseCursor
...@@ -436,6 +448,7 @@ class ButtonStyle with Diagnosticable { ...@@ -436,6 +448,7 @@ class ButtonStyle with Diagnosticable {
properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('minimumSize', minimumSize, defaultValue: null)); properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('minimumSize', minimumSize, defaultValue: null));
properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('fixedSize', fixedSize, defaultValue: null)); properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('fixedSize', fixedSize, defaultValue: null));
properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('maximumSize', maximumSize, defaultValue: null)); properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('maximumSize', maximumSize, defaultValue: null));
properties.add(DiagnosticsProperty<MaterialStateProperty<double?>>('iconSize', iconSize, defaultValue: null));
properties.add(DiagnosticsProperty<MaterialStateProperty<BorderSide?>>('side', side, defaultValue: null)); properties.add(DiagnosticsProperty<MaterialStateProperty<BorderSide?>>('side', side, defaultValue: null));
properties.add(DiagnosticsProperty<MaterialStateProperty<OutlinedBorder?>>('shape', shape, defaultValue: null)); properties.add(DiagnosticsProperty<MaterialStateProperty<OutlinedBorder?>>('shape', shape, defaultValue: null));
properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>('mouseCursor', mouseCursor, defaultValue: null)); properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>('mouseCursor', mouseCursor, defaultValue: null));
...@@ -464,6 +477,7 @@ class ButtonStyle with Diagnosticable { ...@@ -464,6 +477,7 @@ class ButtonStyle with Diagnosticable {
minimumSize: _lerpProperties<Size?>(a?.minimumSize, b?.minimumSize, t, Size.lerp), minimumSize: _lerpProperties<Size?>(a?.minimumSize, b?.minimumSize, t, Size.lerp),
fixedSize: _lerpProperties<Size?>(a?.fixedSize, b?.fixedSize, t, Size.lerp), fixedSize: _lerpProperties<Size?>(a?.fixedSize, b?.fixedSize, t, Size.lerp),
maximumSize: _lerpProperties<Size?>(a?.maximumSize, b?.maximumSize, t, Size.lerp), maximumSize: _lerpProperties<Size?>(a?.maximumSize, b?.maximumSize, t, Size.lerp),
iconSize: _lerpProperties<double?>(a?.iconSize, b?.iconSize, t, lerpDouble),
side: _lerpSides(a?.side, b?.side, t), side: _lerpSides(a?.side, b?.side, t),
shape: MaterialStateProperty.lerp<OutlinedBorder?>(a?.shape, b?.shape, t, OutlinedBorder.lerp), shape: MaterialStateProperty.lerp<OutlinedBorder?>(a?.shape, b?.shape, t, OutlinedBorder.lerp),
mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor, mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor,
......
...@@ -281,6 +281,7 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat ...@@ -281,6 +281,7 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat
final Size? resolvedMinimumSize = resolve<Size?>((ButtonStyle? style) => style?.minimumSize); final Size? resolvedMinimumSize = resolve<Size?>((ButtonStyle? style) => style?.minimumSize);
final Size? resolvedFixedSize = resolve<Size?>((ButtonStyle? style) => style?.fixedSize); final Size? resolvedFixedSize = resolve<Size?>((ButtonStyle? style) => style?.fixedSize);
final Size? resolvedMaximumSize = resolve<Size?>((ButtonStyle? style) => style?.maximumSize); final Size? resolvedMaximumSize = resolve<Size?>((ButtonStyle? style) => style?.maximumSize);
final double? resolvedIconSize = resolve<double?>((ButtonStyle? style) => style?.iconSize);
final BorderSide? resolvedSide = resolve<BorderSide?>((ButtonStyle? style) => style?.side); final BorderSide? resolvedSide = resolve<BorderSide?>((ButtonStyle? style) => style?.side);
final OutlinedBorder? resolvedShape = resolve<OutlinedBorder?>((ButtonStyle? style) => style?.shape); final OutlinedBorder? resolvedShape = resolve<OutlinedBorder?>((ButtonStyle? style) => style?.shape);
...@@ -393,7 +394,7 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat ...@@ -393,7 +394,7 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat
customBorder: resolvedShape.copyWith(side: resolvedSide), customBorder: resolvedShape.copyWith(side: resolvedSide),
statesController: statesController, statesController: statesController,
child: IconTheme.merge( child: IconTheme.merge(
data: IconThemeData(color: resolvedForegroundColor), data: IconThemeData(color: resolvedForegroundColor, size: resolvedIconSize),
child: Padding( child: Padding(
padding: padding, padding: padding,
child: Align( child: Align(
......
...@@ -27,6 +27,7 @@ void main() { ...@@ -27,6 +27,7 @@ void main() {
expect(style.minimumSize, null); expect(style.minimumSize, null);
expect(style.fixedSize, null); expect(style.fixedSize, null);
expect(style.maximumSize, null); expect(style.maximumSize, null);
expect(style.iconSize, null);
expect(style.side, null); expect(style.side, null);
expect(style.shape, null); expect(style.shape, null);
expect(style.mouseCursor, null); expect(style.mouseCursor, null);
...@@ -62,6 +63,7 @@ void main() { ...@@ -62,6 +63,7 @@ void main() {
minimumSize: MaterialStatePropertyAll<Size>(Size(1.0, 2.0)), minimumSize: MaterialStatePropertyAll<Size>(Size(1.0, 2.0)),
side: MaterialStatePropertyAll<BorderSide>(BorderSide(width: 4.0, color: Color(0xfffffff6))), side: MaterialStatePropertyAll<BorderSide>(BorderSide(width: 4.0, color: Color(0xfffffff6))),
maximumSize: MaterialStatePropertyAll<Size>(Size(100.0, 200.0)), maximumSize: MaterialStatePropertyAll<Size>(Size(100.0, 200.0)),
iconSize: MaterialStatePropertyAll<double>(48.1),
shape: MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()), shape: MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()),
mouseCursor: MaterialStatePropertyAll<MouseCursor>(SystemMouseCursors.forbidden), mouseCursor: MaterialStatePropertyAll<MouseCursor>(SystemMouseCursors.forbidden),
tapTargetSize: MaterialTapTargetSize.shrinkWrap, tapTargetSize: MaterialTapTargetSize.shrinkWrap,
...@@ -85,6 +87,7 @@ void main() { ...@@ -85,6 +87,7 @@ void main() {
'padding: MaterialStatePropertyAll(EdgeInsets.all(1.0))', 'padding: MaterialStatePropertyAll(EdgeInsets.all(1.0))',
'minimumSize: MaterialStatePropertyAll(Size(1.0, 2.0))', 'minimumSize: MaterialStatePropertyAll(Size(1.0, 2.0))',
'maximumSize: MaterialStatePropertyAll(Size(100.0, 200.0))', 'maximumSize: MaterialStatePropertyAll(Size(100.0, 200.0))',
'iconSize: MaterialStatePropertyAll(48.1)',
'side: MaterialStatePropertyAll(BorderSide(Color(0xfffffff6), 4.0, BorderStyle.solid))', 'side: MaterialStatePropertyAll(BorderSide(Color(0xfffffff6), 4.0, BorderStyle.solid))',
'shape: MaterialStatePropertyAll(StadiumBorder(BorderSide(Color(0xff000000), 0.0, BorderStyle.none)))', 'shape: MaterialStatePropertyAll(StadiumBorder(BorderSide(Color(0xff000000), 0.0, BorderStyle.none)))',
'mouseCursor: MaterialStatePropertyAll(SystemMouseCursor(forbidden))', 'mouseCursor: MaterialStatePropertyAll(SystemMouseCursor(forbidden))',
...@@ -106,6 +109,7 @@ void main() { ...@@ -106,6 +109,7 @@ void main() {
const MaterialStateProperty<Size> minimumSize = MaterialStatePropertyAll<Size>(Size(1, 2)); const MaterialStateProperty<Size> minimumSize = MaterialStatePropertyAll<Size>(Size(1, 2));
const MaterialStateProperty<Size> fixedSize = MaterialStatePropertyAll<Size>(Size(3, 4)); const MaterialStateProperty<Size> fixedSize = MaterialStatePropertyAll<Size>(Size(3, 4));
const MaterialStateProperty<Size> maximumSize = MaterialStatePropertyAll<Size>(Size(5, 6)); const MaterialStateProperty<Size> maximumSize = MaterialStatePropertyAll<Size>(Size(5, 6));
const MaterialStateProperty<double> iconSize = MaterialStatePropertyAll<double>(48.0);
const MaterialStateProperty<BorderSide> side = MaterialStatePropertyAll<BorderSide>(BorderSide()); const MaterialStateProperty<BorderSide> side = MaterialStatePropertyAll<BorderSide>(BorderSide());
const MaterialStateProperty<OutlinedBorder> shape = MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()); const MaterialStateProperty<OutlinedBorder> shape = MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder());
const MaterialStateProperty<MouseCursor> mouseCursor = MaterialStatePropertyAll<MouseCursor>(SystemMouseCursors.forbidden); const MaterialStateProperty<MouseCursor> mouseCursor = MaterialStatePropertyAll<MouseCursor>(SystemMouseCursors.forbidden);
...@@ -126,6 +130,7 @@ void main() { ...@@ -126,6 +130,7 @@ void main() {
minimumSize: minimumSize, minimumSize: minimumSize,
fixedSize: fixedSize, fixedSize: fixedSize,
maximumSize: maximumSize, maximumSize: maximumSize,
iconSize: iconSize,
side: side, side: side,
shape: shape, shape: shape,
mouseCursor: mouseCursor, mouseCursor: mouseCursor,
...@@ -149,6 +154,7 @@ void main() { ...@@ -149,6 +154,7 @@ void main() {
minimumSize: minimumSize, minimumSize: minimumSize,
fixedSize: fixedSize, fixedSize: fixedSize,
maximumSize: maximumSize, maximumSize: maximumSize,
iconSize: iconSize,
side: side, side: side,
shape: shape, shape: shape,
mouseCursor: mouseCursor, mouseCursor: mouseCursor,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment