Skip to content

Commit 2fff488

Browse files
authored
Fix train hopping animation status listeners (flutter#178372)
Fixes flutter#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
1 parent 452314c commit 2fff488

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

packages/flutter/lib/src/animation/animations.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ class TrainHoppingAnimation extends Animation<double>
543543
void _statusChangeHandler(AnimationStatus status) {
544544
assert(_currentTrain != null);
545545
if (status != _lastStatus) {
546-
notifyListeners();
546+
notifyStatusListeners(status);
547547
_lastStatus = status;
548548
}
549549
assert(_lastStatus != null);

packages/flutter/test/animation/animations_test.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ void main() {
9999

100100
test('TrainHoppingAnimation', () {
101101
final AnimationController currentTrain = AnimationController(vsync: const TestVSync());
102+
addTearDown(currentTrain.dispose);
102103
final AnimationController nextTrain = AnimationController(vsync: const TestVSync());
104+
addTearDown(nextTrain.dispose);
103105
currentTrain.value = 0.5;
104106
nextTrain.value = 0.75;
105107
bool didSwitchTrains = false;
@@ -133,6 +135,32 @@ void main() {
133135
);
134136
});
135137

138+
// Regression test for https://github.com/flutter/flutter/issues/178336.
139+
test('TrainHoppingAnimation notifies status listeners', () {
140+
final AnimationController controller = AnimationController(
141+
duration: const Duration(milliseconds: 100),
142+
vsync: const TestVSync(),
143+
);
144+
addTearDown(controller.dispose);
145+
146+
final TrainHoppingAnimation animation = TrainHoppingAnimation(
147+
Tween<double>(begin: 1.0, end: -1.0).animate(controller),
148+
Tween<double>(begin: -1.0, end: 1.0).animate(controller),
149+
);
150+
addTearDown(animation.dispose);
151+
152+
final List<AnimationStatus> statusLog = <AnimationStatus>[];
153+
animation.addStatusListener(statusLog.add);
154+
expect(statusLog, isEmpty);
155+
156+
controller.forward();
157+
expect(statusLog, equals(<AnimationStatus>[AnimationStatus.forward]));
158+
statusLog.clear();
159+
160+
controller.reverse();
161+
expect(statusLog, equals(<AnimationStatus>[AnimationStatus.dismissed]));
162+
});
163+
136164
test('AnimationMean control test', () {
137165
final AnimationController left = AnimationController(value: 0.5, vsync: const TestVSync());
138166
final AnimationController right = AnimationController(vsync: const TestVSync());

0 commit comments

Comments
 (0)