Commit 3dc32873 authored by Kyle Bradshaw's avatar Kyle Bradshaw Committed by Ian Hickson

AnimationController reset() method (#13044)

* AnimationController reset() method

Just a simple convenience method to fix #13039

* Added `reset()` test

* More test expectations

Per feedback.

* Removed test print

* Improved documentation of reset()

* Add controller.reverse to test
parent c7c3b606
......@@ -218,6 +218,12 @@ class AnimationController extends Animation<double>
notifyListeners();
_checkStatusChanged();
}
/// Sets the controller's value to [lowerBound], stopping the animation (if
/// in progress), and resetting to its beginning point, or dismissed state.
void reset() {
value = lowerBound;
}
/// The rate of change of [value] per second.
///
......
......@@ -396,6 +396,59 @@ void main() {
expect(controller.value, 1.0);
});
test('resetting animation works at all phases', (){
final List<AnimationStatus> statusLog = <AnimationStatus>[];
final AnimationController controller = new AnimationController(
duration: const Duration(milliseconds: 100),
value: 0.0,
lowerBound: 0.0,
upperBound: 1.0,
vsync: const TestVSync(),
)..addStatusListener(statusLog.add);
expect(controller.value, 0.0);
expect(controller.status, AnimationStatus.dismissed);
controller.reset();
expect(controller.value, 0.0);
expect(controller.status, AnimationStatus.dismissed);
statusLog.clear();
controller.forward();
tick(const Duration(milliseconds: 0));
tick(const Duration(milliseconds: 50));
expect(controller.status, AnimationStatus.forward);
controller.reset();
expect(controller.value, 0.0);
expect(controller.status, AnimationStatus.dismissed);
expect(statusLog, equals(<AnimationStatus>[ AnimationStatus.forward, AnimationStatus.dismissed ]));
controller.value = 1.0;
statusLog.clear();
controller.reverse();
tick(const Duration(milliseconds: 0));
tick(const Duration(milliseconds: 50));
expect(controller.status, AnimationStatus.reverse);
controller.reset();
expect(controller.value, 0.0);
expect(controller.status, AnimationStatus.dismissed);
expect(statusLog, equals(<AnimationStatus>[ AnimationStatus.reverse, AnimationStatus.dismissed ]));
statusLog.clear();
controller.forward();
tick(const Duration(milliseconds: 0));
tick(const Duration(milliseconds: 150));
expect(controller.status, AnimationStatus.completed);
controller.reset();
expect(controller.value, 0.0);
expect(controller.status, AnimationStatus.dismissed);
expect(statusLog, equals(<AnimationStatus>[ AnimationStatus.forward, AnimationStatus.completed, AnimationStatus.dismissed ]));
});
test('setting value directly sets correct status', () {
final AnimationController controller = new AnimationController(
value: 0.0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment