Fix train hopping animation status listeners (#178372)

Fixes https://github.com/flutter/flutter/issues/178336

### Description

- Fixes `TrainHoppingAnimation` to notify status listeners when `status`
changes
- Adds tests

## 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.
- [ ] 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.

<!-- 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:
Kostia Sokolovskyi 2025-11-19 08:12:19 +01:00 committed by GitHub
parent 452314c7d2
commit 2fff488d60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View File

@ -543,7 +543,7 @@ class TrainHoppingAnimation extends Animation<double>
void _statusChangeHandler(AnimationStatus status) {
assert(_currentTrain != null);
if (status != _lastStatus) {
notifyListeners();
notifyStatusListeners(status);
_lastStatus = status;
}
assert(_lastStatus != null);

View File

@ -99,7 +99,9 @@ void main() {
test('TrainHoppingAnimation', () {
final AnimationController currentTrain = AnimationController(vsync: const TestVSync());
addTearDown(currentTrain.dispose);
final AnimationController nextTrain = AnimationController(vsync: const TestVSync());
addTearDown(nextTrain.dispose);
currentTrain.value = 0.5;
nextTrain.value = 0.75;
bool didSwitchTrains = false;
@ -133,6 +135,32 @@ void main() {
);
});
// Regression test for https://github.com/flutter/flutter/issues/178336.
test('TrainHoppingAnimation notifies status listeners', () {
final AnimationController controller = AnimationController(
duration: const Duration(milliseconds: 100),
vsync: const TestVSync(),
);
addTearDown(controller.dispose);
final TrainHoppingAnimation animation = TrainHoppingAnimation(
Tween<double>(begin: 1.0, end: -1.0).animate(controller),
Tween<double>(begin: -1.0, end: 1.0).animate(controller),
);
addTearDown(animation.dispose);
final List<AnimationStatus> statusLog = <AnimationStatus>[];
animation.addStatusListener(statusLog.add);
expect(statusLog, isEmpty);
controller.forward();
expect(statusLog, equals(<AnimationStatus>[AnimationStatus.forward]));
statusLog.clear();
controller.reverse();
expect(statusLog, equals(<AnimationStatus>[AnimationStatus.dismissed]));
});
test('AnimationMean control test', () {
final AnimationController left = AnimationController(value: 0.5, vsync: const TestVSync());
final AnimationController right = AnimationController(vsync: const TestVSync());