From c51ae28d8736304e9ca5fa7c9767728209c12345 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 2 Mar 2016 12:05:16 -0800 Subject: [PATCH] Add "form" parameter to AnimationController forward and reverse Fixes #2324 --- .../src/animation/animation_controller.dart | 8 ++++-- .../animation/animation_controller_test.dart | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/animation/animation_controller.dart b/packages/flutter/lib/src/animation/animation_controller.dart index e4c0b209b7..205ecd4237 100644 --- a/packages/flutter/lib/src/animation/animation_controller.dart +++ b/packages/flutter/lib/src/animation/animation_controller.dart @@ -125,13 +125,17 @@ class AnimationController extends Animation } /// 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); } diff --git a/packages/flutter/test/animation/animation_controller_test.dart b/packages/flutter/test/animation/animation_controller_test.dart index f7f1903f18..b561bffbbc 100644 --- a/packages/flutter/test/animation/animation_controller_test.dart +++ b/packages/flutter/test/animation/animation_controller_test.dart @@ -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 valueLog = []; + List statusLog = []; + 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)); + }); }