Merge pull request #2330 from abarth/forward_from
Add "form" parameter to AnimationController forward and reverse
This commit is contained in:
commit
3d9e70ea27
@ -125,13 +125,17 @@ class AnimationController extends Animation<double>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Starts running this animation forwards (towards the end).
|
/// Starts running this animation forwards (towards the end).
|
||||||
Future forward() {
|
Future forward({ double from }) {
|
||||||
|
if (from != null)
|
||||||
|
value = from;
|
||||||
_direction = _AnimationDirection.forward;
|
_direction = _AnimationDirection.forward;
|
||||||
return animateTo(upperBound);
|
return animateTo(upperBound);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Starts running this animation in reverse (towards the beginning).
|
/// Starts running this animation in reverse (towards the beginning).
|
||||||
Future reverse() {
|
Future reverse({ double from }) {
|
||||||
|
if (from != null)
|
||||||
|
value = from;
|
||||||
_direction = _AnimationDirection.reverse;
|
_direction = _AnimationDirection.reverse;
|
||||||
return animateTo(lowerBound);
|
return animateTo(lowerBound);
|
||||||
}
|
}
|
||||||
|
@ -102,4 +102,32 @@ void main() {
|
|||||||
|
|
||||||
controller.stop();
|
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));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user