Added iconSize parameter in ButtonStyle (#108268)
* Added iconSize parameter in ButtonStyle Co-authored-by: Qun Cheng <quncheng@google.com>
This commit is contained in:
parent
5f67b47e23
commit
606954d116
@ -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<Size?>? maximumSize;
|
||||
|
||||
/// The icon's size inside of the button.
|
||||
final MaterialStateProperty<double?>? 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<Size?>? minimumSize,
|
||||
MaterialStateProperty<Size?>? fixedSize,
|
||||
MaterialStateProperty<Size?>? maximumSize,
|
||||
MaterialStateProperty<double?>? iconSize,
|
||||
MaterialStateProperty<BorderSide?>? side,
|
||||
MaterialStateProperty<OutlinedBorder?>? shape,
|
||||
MaterialStateProperty<MouseCursor?>? 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<Object?> values = <Object?>[
|
||||
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<MaterialStateProperty<Size?>>('minimumSize', minimumSize, defaultValue: null));
|
||||
properties.add(DiagnosticsProperty<MaterialStateProperty<Size?>>('fixedSize', fixedSize, 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<OutlinedBorder?>>('shape', shape, defaultValue: null));
|
||||
properties.add(DiagnosticsProperty<MaterialStateProperty<MouseCursor?>>('mouseCursor', mouseCursor, defaultValue: null));
|
||||
@ -464,6 +477,7 @@ class ButtonStyle with Diagnosticable {
|
||||
minimumSize: _lerpProperties<Size?>(a?.minimumSize, b?.minimumSize, t, Size.lerp),
|
||||
fixedSize: _lerpProperties<Size?>(a?.fixedSize, b?.fixedSize, 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),
|
||||
shape: MaterialStateProperty.lerp<OutlinedBorder?>(a?.shape, b?.shape, t, OutlinedBorder.lerp),
|
||||
mouseCursor: t < 0.5 ? a?.mouseCursor : b?.mouseCursor,
|
||||
|
@ -281,6 +281,7 @@ class _ButtonStyleState extends State<ButtonStyleButton> with TickerProviderStat
|
||||
final Size? resolvedMinimumSize = resolve<Size?>((ButtonStyle? style) => style?.minimumSize);
|
||||
final Size? resolvedFixedSize = resolve<Size?>((ButtonStyle? style) => style?.fixedSize);
|
||||
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 OutlinedBorder? resolvedShape = resolve<OutlinedBorder?>((ButtonStyle? style) => style?.shape);
|
||||
|
||||
@ -393,7 +394,7 @@ class _ButtonStyleState extends State<ButtonStyleButton> 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(
|
||||
|
@ -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>(Size(1.0, 2.0)),
|
||||
side: MaterialStatePropertyAll<BorderSide>(BorderSide(width: 4.0, color: Color(0xfffffff6))),
|
||||
maximumSize: MaterialStatePropertyAll<Size>(Size(100.0, 200.0)),
|
||||
iconSize: MaterialStatePropertyAll<double>(48.1),
|
||||
shape: MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder()),
|
||||
mouseCursor: MaterialStatePropertyAll<MouseCursor>(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<Size> minimumSize = MaterialStatePropertyAll<Size>(Size(1, 2));
|
||||
const MaterialStateProperty<Size> fixedSize = MaterialStatePropertyAll<Size>(Size(3, 4));
|
||||
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<OutlinedBorder> shape = MaterialStatePropertyAll<OutlinedBorder>(StadiumBorder());
|
||||
const MaterialStateProperty<MouseCursor> mouseCursor = MaterialStatePropertyAll<MouseCursor>(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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user