mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix ChipThemeData lerp for BorderSide (#173160)
In https://github.com/flutter/flutter/pull/171945#discussion_r2245715705 we realised that some `lerp` method for `BorderSide` had a bug. This PR - Fixes a wrong interpolation of `ChipThemeData.lerp` for `side` in the case of `b` being `null` - Do some cleaning of other `lerp` of `BorderSide?` Fixes https://github.com/flutter/flutter/issues/173161 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
parent
34c2a3b158
commit
dd7b2130a1
@ -776,7 +776,7 @@ class ButtonStyle with Diagnosticable {
|
||||
iconColor: MaterialStateProperty.lerp<Color?>(a?.iconColor, b?.iconColor, t, Color.lerp),
|
||||
iconSize: MaterialStateProperty.lerp<double?>(a?.iconSize, b?.iconSize, t, lerpDouble),
|
||||
iconAlignment: t < 0.5 ? a?.iconAlignment : b?.iconAlignment,
|
||||
side: _lerpSides(a?.side, b?.side, t),
|
||||
side: WidgetStateBorderSide.lerp(a?.side, b?.side, t),
|
||||
shape: MaterialStateProperty.lerp<OutlinedBorder?>(
|
||||
a?.shape,
|
||||
b?.shape,
|
||||
@ -794,16 +794,4 @@ class ButtonStyle with Diagnosticable {
|
||||
foregroundBuilder: t < 0.5 ? a?.foregroundBuilder : b?.foregroundBuilder,
|
||||
);
|
||||
}
|
||||
|
||||
// Special case because BorderSide.lerp() doesn't support null arguments
|
||||
static MaterialStateProperty<BorderSide?>? _lerpSides(
|
||||
MaterialStateProperty<BorderSide?>? a,
|
||||
MaterialStateProperty<BorderSide?>? b,
|
||||
double t,
|
||||
) {
|
||||
if (a == null && b == null) {
|
||||
return null;
|
||||
}
|
||||
return MaterialStateBorderSide.lerp(a, b, t);
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,19 +235,19 @@ class CheckboxThemeData with Diagnosticable {
|
||||
|
||||
// Special case because BorderSide.lerp() doesn't support null arguments
|
||||
static BorderSide? _lerpSides(BorderSide? a, BorderSide? b, double t) {
|
||||
if (a == null || b == null) {
|
||||
if (a == null && b == null) {
|
||||
return null;
|
||||
}
|
||||
if (identical(a, b)) {
|
||||
return a;
|
||||
if (a is WidgetStateBorderSide) {
|
||||
a = a.resolve(const <WidgetState>{});
|
||||
}
|
||||
if (a is MaterialStateBorderSide) {
|
||||
a = a.resolve(<WidgetState>{});
|
||||
if (b is WidgetStateBorderSide) {
|
||||
b = b.resolve(const <WidgetState>{});
|
||||
}
|
||||
if (b is MaterialStateBorderSide) {
|
||||
b = b.resolve(<WidgetState>{});
|
||||
}
|
||||
return BorderSide.lerp(a!, b!, t);
|
||||
a ??= BorderSide(width: 0, color: b!.color.withAlpha(0));
|
||||
b ??= BorderSide(width: 0, color: a.color.withAlpha(0));
|
||||
|
||||
return BorderSide.lerp(a, b, t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -539,7 +539,7 @@ class ChipThemeData with Diagnosticable {
|
||||
labelPadding: EdgeInsetsGeometry.lerp(a?.labelPadding, b?.labelPadding, t),
|
||||
padding: EdgeInsetsGeometry.lerp(a?.padding, b?.padding, t),
|
||||
side: _lerpSides(a?.side, b?.side, t),
|
||||
shape: _lerpShapes(a?.shape, b?.shape, t),
|
||||
shape: OutlinedBorder.lerp(a?.shape, b?.shape, t),
|
||||
labelStyle: TextStyle.lerp(a?.labelStyle, b?.labelStyle, t),
|
||||
secondaryLabelStyle: TextStyle.lerp(a?.secondaryLabelStyle, b?.secondaryLabelStyle, t),
|
||||
brightness: t < 0.5 ? a?.brightness ?? Brightness.light : b?.brightness ?? Brightness.light,
|
||||
@ -566,27 +566,16 @@ class ChipThemeData with Diagnosticable {
|
||||
if (a == null && b == null) {
|
||||
return null;
|
||||
}
|
||||
if (a is MaterialStateBorderSide) {
|
||||
a = a.resolve(<WidgetState>{});
|
||||
if (a is WidgetStateBorderSide) {
|
||||
a = a.resolve(const <WidgetState>{});
|
||||
}
|
||||
if (b is MaterialStateBorderSide) {
|
||||
b = b.resolve(<WidgetState>{});
|
||||
if (b is WidgetStateBorderSide) {
|
||||
b = b.resolve(const <WidgetState>{});
|
||||
}
|
||||
if (a == null) {
|
||||
return BorderSide.lerp(BorderSide(width: 0, color: b!.color.withAlpha(0)), b, t);
|
||||
}
|
||||
if (b == null) {
|
||||
return BorderSide.lerp(BorderSide(width: 0, color: a.color.withAlpha(0)), a, t);
|
||||
}
|
||||
return BorderSide.lerp(a, b, t);
|
||||
}
|
||||
a ??= BorderSide(width: 0, color: b!.color.withAlpha(0));
|
||||
b ??= BorderSide(width: 0, color: a.color.withAlpha(0));
|
||||
|
||||
// TODO(perclasson): OutlinedBorder needs a lerp method - https://github.com/flutter/flutter/issues/60555.
|
||||
static OutlinedBorder? _lerpShapes(OutlinedBorder? a, OutlinedBorder? b, double t) {
|
||||
if (a == null && b == null) {
|
||||
return null;
|
||||
}
|
||||
return ShapeBorder.lerp(a, b, t) as OutlinedBorder?;
|
||||
return BorderSide.lerp(a, b, t);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -155,7 +155,7 @@ class SearchBarThemeData with Diagnosticable {
|
||||
t,
|
||||
Color.lerp,
|
||||
),
|
||||
side: _lerpSides(a?.side, b?.side, t),
|
||||
side: MaterialStateBorderSide.lerp(a?.side, b?.side, t),
|
||||
shape: MaterialStateProperty.lerp<OutlinedBorder?>(
|
||||
a?.shape,
|
||||
b?.shape,
|
||||
@ -304,18 +304,6 @@ class SearchBarThemeData with Diagnosticable {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Special case because BorderSide.lerp() doesn't support null arguments
|
||||
static MaterialStateProperty<BorderSide?>? _lerpSides(
|
||||
MaterialStateProperty<BorderSide?>? a,
|
||||
MaterialStateProperty<BorderSide?>? b,
|
||||
double t,
|
||||
) {
|
||||
if (identical(a, b)) {
|
||||
return a;
|
||||
}
|
||||
return MaterialStateBorderSide.lerp(a, b, t);
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies a search bar theme to descendant [SearchBar] widgets.
|
||||
|
||||
@ -225,12 +225,18 @@ class SearchViewThemeData with Diagnosticable {
|
||||
|
||||
// Special case because BorderSide.lerp() doesn't support null arguments
|
||||
static BorderSide? _lerpSides(BorderSide? a, BorderSide? b, double t) {
|
||||
if (a == null || b == null) {
|
||||
if (a == null && b == null) {
|
||||
return null;
|
||||
}
|
||||
if (identical(a, b)) {
|
||||
return a;
|
||||
if (a is WidgetStateBorderSide) {
|
||||
a = a.resolve(const <WidgetState>{});
|
||||
}
|
||||
if (b is WidgetStateBorderSide) {
|
||||
b = b.resolve(const <WidgetState>{});
|
||||
}
|
||||
a ??= BorderSide(width: 0, color: b!.color.withAlpha(0));
|
||||
b ??= BorderSide(width: 0, color: a.color.withAlpha(0));
|
||||
|
||||
return BorderSide.lerp(a, b, t);
|
||||
}
|
||||
}
|
||||
|
||||
@ -582,6 +582,9 @@ abstract class WidgetStateBorderSide extends BorderSide
|
||||
if (a == null && b == null) {
|
||||
return null;
|
||||
}
|
||||
if (identical(a, b)) {
|
||||
return a;
|
||||
}
|
||||
return _LerpSides(a, b, t);
|
||||
}
|
||||
}
|
||||
|
||||
@ -458,8 +458,44 @@ void main() {
|
||||
lerped.shape,
|
||||
const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(2.0))),
|
||||
);
|
||||
// Returns null if either lerp value is null.
|
||||
expect(lerped.side, null);
|
||||
expect(lerped.side!.width, 2.0);
|
||||
expect(lerped.side!.color, isSameColorAs(const Color(0x80000000)));
|
||||
});
|
||||
|
||||
test('CheckboxThemeData lerp from null to populated parameters', () {
|
||||
final CheckboxThemeData theme = CheckboxThemeData(
|
||||
fillColor: MaterialStateProperty.all(const Color(0xfffffff0)),
|
||||
checkColor: MaterialStateProperty.all(const Color(0xfffffff1)),
|
||||
overlayColor: MaterialStateProperty.all(const Color(0xfffffff2)),
|
||||
splashRadius: 4.0,
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
visualDensity: const VisualDensity(vertical: 1.0, horizontal: 1.0),
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(4.0))),
|
||||
side: const BorderSide(width: 4.0),
|
||||
);
|
||||
final CheckboxThemeData lerped = CheckboxThemeData.lerp(null, theme, 0.25);
|
||||
|
||||
expect(
|
||||
lerped.fillColor!.resolve(const <MaterialState>{}),
|
||||
isSameColorAs(const Color(0x40fffff0)),
|
||||
);
|
||||
expect(
|
||||
lerped.checkColor!.resolve(const <MaterialState>{}),
|
||||
isSameColorAs(const Color(0x40fffff1)),
|
||||
);
|
||||
expect(
|
||||
lerped.overlayColor!.resolve(const <MaterialState>{}),
|
||||
isSameColorAs(const Color(0x40fffff2)),
|
||||
);
|
||||
expect(lerped.splashRadius, 1);
|
||||
expect(lerped.materialTapTargetSize, null);
|
||||
expect(lerped.visualDensity, null);
|
||||
expect(
|
||||
lerped.shape,
|
||||
const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(1.0))),
|
||||
);
|
||||
expect(lerped.side!.width, 1.0);
|
||||
expect(lerped.side!.color, isSameColorAs(const Color(0x40000000)));
|
||||
});
|
||||
|
||||
test('CheckboxThemeData lerp from populated parameters', () {
|
||||
|
||||
@ -738,7 +738,7 @@ void main() {
|
||||
expect(lerpBNull25.showCheckmark, equals(false));
|
||||
expect(lerpBNull25.labelPadding, equals(const EdgeInsets.only(left: 6.0, right: 6.0)));
|
||||
expect(lerpBNull25.padding, equals(const EdgeInsets.all(3.0)));
|
||||
expect(lerpBNull25.side!.color, isSameColorAs(Colors.black.withAlpha(0x3f)));
|
||||
expect(lerpBNull25.side!.color, isSameColorAs(Colors.black.withAlpha(0xbf)));
|
||||
expect(lerpBNull25.shape, isA<StadiumBorder>());
|
||||
expect(lerpBNull25.labelStyle?.color, isSameColorAs(Colors.white.withAlpha(0xa7)));
|
||||
expect(lerpBNull25.secondaryLabelStyle?.color, isSameColorAs(Colors.black.withAlpha(0xa7)));
|
||||
@ -760,7 +760,7 @@ void main() {
|
||||
expect(lerpBNull75.showCheckmark, equals(true));
|
||||
expect(lerpBNull75.labelPadding, equals(const EdgeInsets.only(left: 2.0, right: 2.0)));
|
||||
expect(lerpBNull75.padding, equals(const EdgeInsets.all(1.0)));
|
||||
expect(lerpBNull75.side!.color, isSameColorAs(Colors.black.withAlpha(0xbf)));
|
||||
expect(lerpBNull75.side!.color, isSameColorAs(Colors.black.withAlpha(0x3f)));
|
||||
expect(lerpBNull75.shape, isA<StadiumBorder>());
|
||||
expect(lerpBNull75.labelStyle?.color, isSameColorAs(Colors.white.withAlpha(0x38)));
|
||||
expect(lerpBNull75.secondaryLabelStyle?.color, isSameColorAs(Colors.black.withAlpha(0x38)));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user