AnimatedPageDragger constructor

AnimatedPageDragger({
  1. required SlideDirection slideDirection,
  2. required TransitionGoal transitionGoal,
  3. required double slidePercentVer,
  4. required double slidePercentHor,
  5. required LiquidProvider slideUpdateStream,
  6. required TickerProvider vsync,
})

Constructor

Implementation

AnimatedPageDragger({
  required this.slideDirection,
  required this.transitionGoal,
  required double slidePercentVer,
  required double slidePercentHor,
  required LiquidProvider slideUpdateStream,
  required TickerProvider vsync,
}) {
  final startSlidePercentHor = slidePercentHor;
  final startSlidePercentVer = slidePercentVer;
  double? endSlidePercentHor, endSlidePercentVer;
  Duration duration;

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

    endSlidePercentVer = slideUpdateStream.positionSlideIcon;

    final slideRemaining = 1.0 - slidePercentHor;
    //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 {
    endSlidePercentHor = endSlidePercentVer = 0.0;

    duration = Duration(
      milliseconds: (slidePercentHor / 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(
        startSlidePercentHor,
        endSlidePercentHor,
        completionAnimationController.value,
      );
      final slidePercentVer = lerpDouble(
        startSlidePercentVer,
        endSlidePercentVer,
        completionAnimationController.value,
      );
      //Adding to slide update stream
      slideUpdateStream.updateSlide(SlideUpdate(
        slideDirection,
        slidePercent ?? 0,
        slidePercentVer ?? 0,
        UpdateType.animating,
      ));
    })
    ..addStatusListener((AnimationStatus status) {
      //When animation has done executing
      if (status == AnimationStatus.completed) {
        //Adding to slide update stream
        slideUpdateStream.updateSlide(SlideUpdate(
          slideDirection,
          slidePercentHor,
          slidePercentVer,
          UpdateType.doneAnimating,
        ));
      }
    });
}