animateTo method
Future<void>
animateTo({
- required int index,
- Duration? delay,
- Duration duration = const Duration(milliseconds: 150),
- Curve curve = Curves.easeIn,
override
Animate to the step index. If the current step index equals the provided step index nothing will happen.
Implementation
@override
Future<void> animateTo({
required int index,
Duration? delay,
Duration duration = const Duration(milliseconds: 150),
Curve curve = Curves.easeIn,
}) async {
if (this.index == index || !getIsAnimateToEnabled(index)) {
return;
}
final delayUntil = DateTime.now().add(duration);
final oldIndex = this.index;
final newIndex = index;
if (_onStepChanged != null) {
await _onStepChanged!(
oldIndex,
index,
);
}
final now = DateTime.now();
if (delay != null && delayUntil.isAfter(now)) {
final realDelay = Duration(
milliseconds:
delayUntil.millisecondsSinceEpoch - now.millisecondsSinceEpoch,
);
await Future.delayed(realDelay);
}
_index.add(newIndex);
await Future.wait([
stepControllers[newIndex].step.onShowing(),
stepControllers[oldIndex].step.onHiding(),
pageController.animateToPage(
newIndex,
duration: duration,
curve: curve,
),
]);
await Future.wait([
stepControllers[newIndex].step.onShowingCompleted(),
stepControllers[oldIndex].step.onHidingCompleted(),
]);
}