Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 606954d

Browse files
authored
Added iconSize parameter in ButtonStyle (#108268)
* Added iconSize parameter in ButtonStyle Co-authored-by: Qun Cheng <[email protected]>
1 parent 5f67b47 commit 606954d

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

packages/flutter/lib/src/material/button_style.dart

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class ButtonStyle with Diagnosticable {
132132
this.minimumSize,
133133
this.fixedSize,
134134
this.maximumSize,
135+
this.iconSize,
135136
this.side,
136137
this.shape,
137138
this.mouseCursor,
@@ -210,6 +211,9 @@ class ButtonStyle with Diagnosticable {
210211
/// This value must be greater than or equal to [minimumSize].
211212
final MaterialStateProperty<Size?>? maximumSize;
212213

214+
/// The icon's size inside of the button.
215+
final MaterialStateProperty<double?>? iconSize;
216+
213217
/// The color and weight of the button's outline.
214218
///
215219
/// This value is combined with [shape] to create a shape decorated
@@ -300,6 +304,7 @@ class ButtonStyle with Diagnosticable {
300304
MaterialStateProperty<Size?>? minimumSize,
301305
MaterialStateProperty<Size?>? fixedSize,
302306
MaterialStateProperty<Size?>? maximumSize,
307+
MaterialStateProperty<double?>? iconSize,
303308
MaterialStateProperty<BorderSide?>? side,
304309
MaterialStateProperty<OutlinedBorder?>? shape,
305310
MaterialStateProperty<MouseCursor?>? mouseCursor,
@@ -322,6 +327,7 @@ class ButtonStyle with Diagnosticable {
322327
minimumSize: minimumSize ?? this.minimumSize,
323328
fixedSize: fixedSize ?? this.fixedSize,
324329
maximumSize: maximumSize ?? this.maximumSize,
330+
iconSize: iconSize ?? this.iconSize,
325331
side: side ?? this.side,
326332
shape: shape ?? this.shape,
327333
mouseCursor: mouseCursor ?? this.mouseCursor,
@@ -355,6 +361,7 @@ class ButtonStyle with Diagnosticable {
355361
minimumSize: minimumSize ?? style.minimumSize,
356362
fixedSize: fixedSize ?? style.fixedSize,
357363
maximumSize: maximumSize ?? style.maximumSize,
364+
iconSize: iconSize ?? style.iconSize,
358365
side: side ?? style.side,
359366
shape: shape ?? style.shape,
360367
mouseCursor: mouseCursor ?? style.mouseCursor,
@@ -368,28 +375,32 @@ class ButtonStyle with Diagnosticable {
368375
}
369376

370377
@override
371-
int get hashCode => Object.hash(
372-
textStyle,
373-
backgroundColor,
374-
foregroundColor,
375-
overlayColor,
376-
shadowColor,
377-
surfaceTintColor,
378-
elevation,
379-
padding,
380-
minimumSize,
381-
fixedSize,
382-
maximumSize,
383-
side,
384-
shape,
385-
mouseCursor,
386-
visualDensity,
387-
tapTargetSize,
388-
animationDuration,
389-
enableFeedback,
390-
alignment,
391-
splashFactory,
392-
);
378+
int get hashCode {
379+
final List<Object?> values = <Object?>[
380+
textStyle,
381+
backgroundColor,
382+
foregroundColor,
383+
overlayColor,
384+
shadowColor,
385+
surfaceTintColor,
386+
elevation,
387+
padding,
388+
minimumSize,
389+
fixedSize,
390+
maximumSize,
391+
iconSize,
392+
side,
393+
shape,
394+
mouseCursor,
395+
visualDensity,
396+
tapTargetSize,
397+
animationDuration,
398+
enableFeedback,
399+
alignment,
400+
splashFactory,
401+
];
402+
return Object.hashAll(values);
403+
}
393404

394405
@override
395406
bool operator ==(Object other) {
@@ -411,6 +422,7 @@ class ButtonStyle with Diagnosticable {
411422
&& other.minimumSize == minimumSize
412423
&& other.fixedSize == fixedSize
413424
&& other.maximumSize == maximumSize
425+
&& other.iconSize == iconSize
414426
&& other.side == side
415427
&& other.shape == shape
416428
&& other.mouseCursor == mouseCursor
@@ -436,6 +448,7 @@ class ButtonStyle with Diagnosticable {
436448
properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('minimumSize', minimumSize, defaultValue: null));
437449
properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('fixedSize', fixedSize, defaultValue: null));
438450
properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('maximumSize', maximumSize, defaultValue: null));
451+
properties.add(DiagnosticsProperty<MaterialStateProperty<double?>>('iconSize', iconSize, defaultValue: null));
439452
properties.add(DiagnosticsProperty<MaterialStateProperty<BorderSide?>>('side', side, defaultValue: null));
440453
properties.add(DiagnosticsProperty<MaterialStateProperty<OutlinedBorder?>>('shape', shape, defaultValue: null));
441454
properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>('mouseCursor', mouseCursor, defaultValue: null));
@@ -464,6 +477,7 @@ class ButtonStyle with Diagnosticable {
464477
minimumSize: _lerpProperties<Size?>(a?.minimumSize, b?.minimumSize, t, Size.lerp),
465478
fixedSize: _lerpProperties<Size?>(a?.fixedSize, b?.fixedSize, t, Size.lerp),
466479
maximumSize: _lerpProperties<Size?>(a?.maximumSize, b?.maximumSize, t, Size.lerp),
480+
iconSize: _lerpProperties<double?>(a?.iconSize, b?.iconSize, t, lerpDouble),
467481
side: _lerpSides(a?.side, b?.side, t),
468482
shape: MaterialStateProperty.lerp<OutlinedBorder?>(a?.shape, b?.shape, t, OutlinedBorder.lerp),
469483
mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor,

packages/flutter/lib/src/material/button_style_button.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat
281281
final Size? resolvedMinimumSize = resolve<Size?>((ButtonStyle? style) => style?.minimumSize);
282282
final Size? resolvedFixedSize = resolve<Size?>((ButtonStyle? style) => style?.fixedSize);
283283
final Size? resolvedMaximumSize = resolve<Size?>((ButtonStyle? style) => style?.maximumSize);
284+
final double? resolvedIconSize = resolve<double?>((ButtonStyle? style) => style?.iconSize);
284285
final BorderSide? resolvedSide = resolve<BorderSide?>((ButtonStyle? style) => style?.side);
285286
final OutlinedBorder? resolvedShape = resolve<OutlinedBorder?>((ButtonStyle? style) => style?.shape);
286287

@@ -393,7 +394,7 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat
393394
customBorder: resolvedShape.copyWith(side: resolvedSide),
394395
statesController: statesController,
395396
child: IconTheme.merge(
396-
data: IconThemeData(color: resolvedForegroundColor),
397+
data: IconThemeData(color: resolvedForegroundColor, size: resolvedIconSize),
397398
child: Padding(
398399
padding: padding,
399400
child: Align(

packages/flutter/test/material/button_style_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ void main() {
2727
expect(style.minimumSize, null);
2828
expect(style.fixedSize, null);
2929
expect(style.maximumSize, null);
30+
expect(style.iconSize, null);
3031
expect(style.side, null);
3132
expect(style.shape, null);
3233
expect(style.mouseCursor, null);
@@ -62,6 +63,7 @@ void main() {
6263
minimumSize: MaterialStatePropertyAll<Size>(Size(1.0, 2.0)),
6364
side: MaterialStatePropertyAll<BorderSide>(BorderSide(width: 4.0, color: Color(0xfffffff6))),
6465
maximumSize: MaterialStatePropertyAll<Size>(Size(100.0, 200.0)),
66+
iconSize: MaterialStatePropertyAll<double>(48.1),
6567
shape: MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()),
6668
mouseCursor: MaterialStatePropertyAll<MouseCursor>(SystemMouseCursors.forbidden),
6769
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
@@ -85,6 +87,7 @@ void main() {
8587
'padding: MaterialStatePropertyAll(EdgeInsets.all(1.0))',
8688
'minimumSize: MaterialStatePropertyAll(Size(1.0, 2.0))',
8789
'maximumSize: MaterialStatePropertyAll(Size(100.0, 200.0))',
90+
'iconSize: MaterialStatePropertyAll(48.1)',
8891
'side: MaterialStatePropertyAll(BorderSide(Color(0xfffffff6), 4.0, BorderStyle.solid))',
8992
'shape: MaterialStatePropertyAll(StadiumBorder(BorderSide(Color(0xff000000), 0.0, BorderStyle.none)))',
9093
'mouseCursor: MaterialStatePropertyAll(SystemMouseCursor(forbidden))',
@@ -106,6 +109,7 @@ void main() {
106109
const MaterialStateProperty<Size> minimumSize = MaterialStatePropertyAll<Size>(Size(1, 2));
107110
const MaterialStateProperty<Size> fixedSize = MaterialStatePropertyAll<Size>(Size(3, 4));
108111
const MaterialStateProperty<Size> maximumSize = MaterialStatePropertyAll<Size>(Size(5, 6));
112+
const MaterialStateProperty<double> iconSize = MaterialStatePropertyAll<double>(48.0);
109113
const MaterialStateProperty<BorderSide> side = MaterialStatePropertyAll<BorderSide>(BorderSide());
110114
const MaterialStateProperty<OutlinedBorder> shape = MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder());
111115
const MaterialStateProperty<MouseCursor> mouseCursor = MaterialStatePropertyAll<MouseCursor>(SystemMouseCursors.forbidden);
@@ -126,6 +130,7 @@ void main() {
126130
minimumSize: minimumSize,
127131
fixedSize: fixedSize,
128132
maximumSize: maximumSize,
133+
iconSize: iconSize,
129134
side: side,
130135
shape: shape,
131136
mouseCursor: mouseCursor,
@@ -149,6 +154,7 @@ void main() {
149154
minimumSize: minimumSize,
150155
fixedSize: fixedSize,
151156
maximumSize: maximumSize,
157+
iconSize: iconSize,
152158
side: side,
153159
shape: shape,
154160
mouseCursor: mouseCursor,

0 commit comments

Comments
 (0)