diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index bcf68c1edc9..b65ed44d04e 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -218,7 +218,9 @@ class _BorderContainerState extends State<_BorderContainer> with TickerProviderS ); _border = _InputBorderTween(begin: widget.border, end: widget.border); _hoverAnimation = CurvedAnimation(parent: _hoverColorController, curve: Curves.linear); - _hoverColorTween = ColorTween(begin: Colors.transparent, end: widget.hoverColor); + + // Animate between transparent [widget.hoverColor] and [widget.hoverColor]. + _hoverColorTween = ColorTween(begin: widget.hoverColor.withAlpha(0), end: widget.hoverColor); } @override @@ -240,7 +242,8 @@ class _BorderContainerState extends State<_BorderContainer> with TickerProviderS ..forward(); } if (widget.hoverColor != oldWidget.hoverColor) { - _hoverColorTween = ColorTween(begin: Colors.transparent, end: widget.hoverColor); + // Animate between transparent [widget.hoverColor] and [widget.hoverColor]. + _hoverColorTween = ColorTween(begin: widget.hoverColor.withAlpha(0), end: widget.hoverColor); } if (widget.isHovering != oldWidget.isHovering) { if (widget.isHovering) { diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index 6b2ff3824b5..49da3d42029 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -238,6 +238,14 @@ Rect getContainerRect(WidgetTester tester) { return box.paintBounds; } +Animation _getHoverAnimation(WidgetTester tester) { + final CustomPaint customPaint = tester.widget(findBorderPainter()); + final dynamic /*_InputBorderPainter*/ inputBorderPainter = customPaint.foregroundPainter; + // ignore: avoid_dynamic_calls + final Animation animation = inputBorderPainter.hoverAnimation as Animation; + return animation; +} + InputBorder? getBorder(WidgetTester tester) { if (!tester.any(findBorderPainter())) { return null; @@ -13361,6 +13369,15 @@ void main() { await tester.pump(const Duration(milliseconds: 15)); expect(getContainerColor(tester), isSameColorAs(fillColor)); + // Test that for high refresh rate displays, the color mid-animation is somewhere between + // the fill color and the hover color. + await pumpDecorator(hovering: true); + expect(getContainerColor(tester), isSameColorAs(fillColor)); + await tester.pump(const Duration(milliseconds: 6)); + final Color midHoverColor = + Color.lerp(hoverColor.withAlpha(0), hoverColor, _getHoverAnimation(tester).value)!; + expect(getContainerColor(tester), isSameColorAs(Color.alphaBlend(midHoverColor, fillColor))); + await pumpDecorator(hovering: false, enabled: false); expect(getContainerColor(tester), isSameColorAs(disabledColor)); await tester.pump(const Duration(seconds: 10));