AnimatedPageDragger constructor

AnimatedPageDragger({
  1. SlideDirection? slideDirection,
  2. TransitionGoal? transitionGoal,
  3. double? slidePercent,
  4. StreamController<SlideUpdate>? slideUpdateStream,
  5. TickerProvider? vsync,
})

Implementation

AnimatedPageDragger({
  this.slideDirection,
  this.transitionGoal,
  double? slidePercent,
  StreamController<SlideUpdate>? slideUpdateStream,
  TickerProvider? vsync,
}) {
  final startSlidePercent = slidePercent;
  double endSlidePercent;
  Duration duration;

  //We have to complete the page reveal
  if (transitionGoal == TransitionGoal.open) {
    endSlidePercent = 1.0;

    final slideRemaining = 1.0 - slidePercent!;
    //Standard value take for drag velocity to avoid complex calculations.
    duration = Duration(
        milliseconds: (slideRemaining / PERCENT_PER_MILLISECOND).round());
  }
  //We have to close the page reveal
  else {
    endSlidePercent = 0.0;

    duration = Duration(
        milliseconds: (slidePercent! / PERCENT_PER_MILLISECOND).round());
  }

  //Adding listener to animation controller
  //Also value to animation controller vary from 0.0 to 1.0 according to duration.
  completionAnimationController = AnimationController(
      duration: duration, vsync: vsync!)
    ..addListener(() {
      final slidePercent = lerpDouble(startSlidePercent, endSlidePercent,
          completionAnimationController!.value);

      //Adding to slide update stream
      slideUpdateStream!.add(
          SlideUpdate(slideDirection!, slidePercent!, UpdateType.animating));
    })
    ..addStatusListener((AnimationStatus status) {
      //When animation has done executing
      if (status == AnimationStatus.completed) {
        //Adding to slide update stream
        slideUpdateStream!.add(SlideUpdate(
            slideDirection!, slidePercent, UpdateType.doneAnimating));
      }
    });
}