mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
InputDecorator - animate between transparent hoverColor and hoverColor (#168244)
<!-- Thanks for filing a pull request! Reviewers are typically assigned within a week of filing a request. To learn more about code review, see our documentation on Tree Hygiene: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md --> As described in https://github.com/flutter/flutter/issues/155169, TextFields with hoverColor set can have an issue where they flicker as the mouse enters and exits their bounds. _BorderContainerState uses a 15ms animation to transition between non-hovered and hovered states. Part of this animation is a ColorTween between Colors.transparent and a given hoverColor. Critically, Colors.transparent is transparent black. On high refresh rate displays (any display with faster than 60z), this can result in a frame being rendered where the TextField fill color is a dark, semi-transparent version of hoverColor. The immediate solution to this is to animate between hoverColor and a hoverColor with alpha 0. Before: https://github.com/user-attachments/assets/01d62c6a-015d-4dc7-9897-7c3a75ca8aa0 After: https://github.com/user-attachments/assets/ff51a5b2-ba4a-4508-a111-4c915d31ac46 Fixes https://github.com/flutter/flutter/issues/155169 ## 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]. <!-- 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 --------- Co-authored-by: Nick Sparks <6109599+nsparks@users.noreply.github.com>
This commit is contained in:
parent
9f42991d77
commit
bc0d3289cb
@ -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) {
|
||||
|
||||
@ -238,6 +238,14 @@ Rect getContainerRect(WidgetTester tester) {
|
||||
return box.paintBounds;
|
||||
}
|
||||
|
||||
Animation<double> _getHoverAnimation(WidgetTester tester) {
|
||||
final CustomPaint customPaint = tester.widget(findBorderPainter());
|
||||
final dynamic /*_InputBorderPainter*/ inputBorderPainter = customPaint.foregroundPainter;
|
||||
// ignore: avoid_dynamic_calls
|
||||
final Animation<double> animation = inputBorderPainter.hoverAnimation as Animation<double>;
|
||||
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));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user