From 9e45b85e728feaa085dc4d4bb07f3a2966d4fcbd Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 24 Feb 2016 12:15:57 -0800 Subject: [PATCH] Keep AnimationController's _value in bounds Rather than clamping _value on read, we now clamp the value when writing it, which simplifies reasoning about _value. --- .../flutter/lib/src/animation/animation_controller.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/animation/animation_controller.dart b/packages/flutter/lib/src/animation/animation_controller.dart index e0aee1c9783..ca9a49c0d4d 100644 --- a/packages/flutter/lib/src/animation/animation_controller.dart +++ b/packages/flutter/lib/src/animation/animation_controller.dart @@ -88,7 +88,7 @@ class AnimationController extends Animation /// The current value of the animation. /// /// Setting this value stops the current animation. - double get value => _value.clamp(lowerBound, upperBound); + double get value => _value; double _value; void set value(double newValue) { assert(newValue != null); @@ -174,7 +174,7 @@ class AnimationController extends Animation assert(simulation != null); assert(!isAnimating); _simulation = simulation; - _value = simulation.x(0.0); + _value = simulation.x(0.0).clamp(lowerBound, upperBound); return _ticker.start(); } @@ -200,7 +200,7 @@ class AnimationController extends Animation void _tick(Duration elapsed) { double elapsedInSeconds = elapsed.inMicroseconds.toDouble() / Duration.MICROSECONDS_PER_SECOND; - _value = _simulation.x(elapsedInSeconds); + _value = _simulation.x(elapsedInSeconds).clamp(lowerBound, upperBound); if (_simulation.isDone(elapsedInSeconds)) stop(); notifyListeners();