From b6c2335ddf6183810b993f60e4c40ba194aa1ca8 Mon Sep 17 00:00:00 2001 From: Taha Tesser Date: Fri, 26 Aug 2022 19:55:19 +0300 Subject: [PATCH] Replace `_lerpProperties` with `MaterialStateProperty.lerp` in `button_style.dart` (#110323) --- .../lib/src/material/button_style.dart | 48 +++++-------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/packages/flutter/lib/src/material/button_style.dart b/packages/flutter/lib/src/material/button_style.dart index ec5a70657f..b0556b1d1d 100644 --- a/packages/flutter/lib/src/material/button_style.dart +++ b/packages/flutter/lib/src/material/button_style.dart @@ -485,18 +485,18 @@ class ButtonStyle with Diagnosticable { return null; } return ButtonStyle( - textStyle: _lerpProperties(a?.textStyle, b?.textStyle, t, TextStyle.lerp), - backgroundColor: _lerpProperties(a?.backgroundColor, b?.backgroundColor, t, Color.lerp), - foregroundColor: _lerpProperties(a?.foregroundColor, b?.foregroundColor, t, Color.lerp), - overlayColor: _lerpProperties(a?.overlayColor, b?.overlayColor, t, Color.lerp), - shadowColor: _lerpProperties(a?.shadowColor, b?.shadowColor, t, Color.lerp), - surfaceTintColor: _lerpProperties(a?.surfaceTintColor, b?.surfaceTintColor, t, Color.lerp), - elevation: _lerpProperties(a?.elevation, b?.elevation, t, lerpDouble), - padding: _lerpProperties(a?.padding, b?.padding, t, EdgeInsetsGeometry.lerp), - 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), + textStyle: MaterialStateProperty.lerp(a?.textStyle, b?.textStyle, t, TextStyle.lerp), + backgroundColor: MaterialStateProperty.lerp(a?.backgroundColor, b?.backgroundColor, t, Color.lerp), + foregroundColor: MaterialStateProperty.lerp(a?.foregroundColor, b?.foregroundColor, t, Color.lerp), + overlayColor: MaterialStateProperty.lerp(a?.overlayColor, b?.overlayColor, t, Color.lerp), + shadowColor: MaterialStateProperty.lerp(a?.shadowColor, b?.shadowColor, t, Color.lerp), + surfaceTintColor: MaterialStateProperty.lerp(a?.surfaceTintColor, b?.surfaceTintColor, t, Color.lerp), + elevation: MaterialStateProperty.lerp(a?.elevation, b?.elevation, t, lerpDouble), + padding: MaterialStateProperty.lerp(a?.padding, b?.padding, t, EdgeInsetsGeometry.lerp), + minimumSize: MaterialStateProperty.lerp(a?.minimumSize, b?.minimumSize, t, Size.lerp), + fixedSize: MaterialStateProperty.lerp(a?.fixedSize, b?.fixedSize, t, Size.lerp), + maximumSize: MaterialStateProperty.lerp(a?.maximumSize, b?.maximumSize, t, Size.lerp), + iconSize: MaterialStateProperty.lerp(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, @@ -509,14 +509,6 @@ class ButtonStyle with Diagnosticable { ); } - static MaterialStateProperty? _lerpProperties(MaterialStateProperty? a, MaterialStateProperty? b, double t, T? Function(T?, T?, double) lerpFunction ) { - // Avoid creating a _LerpProperties object for a common case. - if (a == null && b == null) { - return null; - } - return _LerpProperties(a, b, t, lerpFunction); - } - // Special case because BorderSide.lerp() doesn't support null arguments static MaterialStateProperty? _lerpSides(MaterialStateProperty? a, MaterialStateProperty? b, double t) { if (a == null && b == null) { @@ -526,22 +518,6 @@ class ButtonStyle with Diagnosticable { } } -class _LerpProperties implements MaterialStateProperty { - const _LerpProperties(this.a, this.b, this.t, this.lerpFunction); - - final MaterialStateProperty? a; - final MaterialStateProperty? b; - final double t; - final T? Function(T?, T?, double) lerpFunction; - - @override - T? resolve(Set states) { - final T? resolvedA = a?.resolve(states); - final T? resolvedB = b?.resolve(states); - return lerpFunction(resolvedA, resolvedB, t); - } -} - class _LerpSides implements MaterialStateProperty { const _LerpSides(this.a, this.b, this.t);