Commit 9e45b85e authored by Adam Barth's avatar Adam Barth

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.
parent df52a77f
...@@ -88,7 +88,7 @@ class AnimationController extends Animation<double> ...@@ -88,7 +88,7 @@ class AnimationController extends Animation<double>
/// The current value of the animation. /// The current value of the animation.
/// ///
/// Setting this value stops the current animation. /// Setting this value stops the current animation.
double get value => _value.clamp(lowerBound, upperBound); double get value => _value;
double _value; double _value;
void set value(double newValue) { void set value(double newValue) {
assert(newValue != null); assert(newValue != null);
...@@ -174,7 +174,7 @@ class AnimationController extends Animation<double> ...@@ -174,7 +174,7 @@ class AnimationController extends Animation<double>
assert(simulation != null); assert(simulation != null);
assert(!isAnimating); assert(!isAnimating);
_simulation = simulation; _simulation = simulation;
_value = simulation.x(0.0); _value = simulation.x(0.0).clamp(lowerBound, upperBound);
return _ticker.start(); return _ticker.start();
} }
...@@ -200,7 +200,7 @@ class AnimationController extends Animation<double> ...@@ -200,7 +200,7 @@ class AnimationController extends Animation<double>
void _tick(Duration elapsed) { void _tick(Duration elapsed) {
double elapsedInSeconds = elapsed.inMicroseconds.toDouble() / Duration.MICROSECONDS_PER_SECOND; double elapsedInSeconds = elapsed.inMicroseconds.toDouble() / Duration.MICROSECONDS_PER_SECOND;
_value = _simulation.x(elapsedInSeconds); _value = _simulation.x(elapsedInSeconds).clamp(lowerBound, upperBound);
if (_simulation.isDone(elapsedInSeconds)) if (_simulation.isDone(elapsedInSeconds))
stop(); stop();
notifyListeners(); notifyListeners();
......
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