Commit 3d9e70ea authored by Adam Barth's avatar Adam Barth

Merge pull request #2330 from abarth/forward_from

Add "form" parameter to AnimationController forward and reverse
parents e802858b c51ae28d
......@@ -125,13 +125,17 @@ class AnimationController extends Animation<double>
}
/// Starts running this animation forwards (towards the end).
Future forward() {
Future forward({ double from }) {
if (from != null)
value = from;
_direction = _AnimationDirection.forward;
return animateTo(upperBound);
}
/// Starts running this animation in reverse (towards the beginning).
Future reverse() {
Future reverse({ double from }) {
if (from != null)
value = from;
_direction = _AnimationDirection.reverse;
return animateTo(lowerBound);
}
......
......@@ -102,4 +102,32 @@ void main() {
controller.stop();
});
test("Forward and reverse from values", () {
WidgetFlutterBinding.ensureInitialized();
AnimationController controller = new AnimationController(
duration: const Duration(milliseconds: 100)
);
List<double> valueLog = <double>[];
List<AnimationStatus> statusLog = <AnimationStatus>[];
controller
..addStatusListener((AnimationStatus status) {
statusLog.add(status);
})
..addListener(() {
valueLog.add(controller.value);
});
controller.reverse(from: 0.2);
expect(statusLog, equals([ AnimationStatus.reverse ]));
expect(valueLog, equals([ 0.2 ]));
expect(controller.value, equals(0.2));
statusLog.clear();
valueLog.clear();
controller.forward(from: 0.0);
expect(statusLog, equals([ AnimationStatus.dismissed, AnimationStatus.forward ]));
expect(valueLog, equals([ 0.0 ]));
expect(controller.value, equals(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