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
This commit is contained in:
parent
c7c3b606fc
commit
3dc32873bf
@ -219,6 +219,12 @@ class AnimationController extends Animation<double>
|
|||||||
_checkStatusChanged();
|
_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.
|
/// The rate of change of [value] per second.
|
||||||
///
|
///
|
||||||
/// If [isAnimating] is false, then [value] is not changing and the rate of
|
/// If [isAnimating] is false, then [value] is not changing and the rate of
|
||||||
|
@ -396,6 +396,59 @@ void main() {
|
|||||||
expect(controller.value, 1.0);
|
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', () {
|
test('setting value directly sets correct status', () {
|
||||||
final AnimationController controller = new AnimationController(
|
final AnimationController controller = new AnimationController(
|
||||||
value: 0.0,
|
value: 0.0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user