updateData method

dynamic updateData(
  1. SlideUpdate event
)

updating data using SlideUpdate, generally we are handling and managing the Animation UpdateType in this methods, All callbacks and factors are also managed by this method.

Implementation

updateData(SlideUpdate event) {
  if (!enableLoop) if (event.direction == SlideDirection.leftToRight &&
      activePageIndex == 0) {
    return;
  } else if (event.direction == SlideDirection.rightToLeft &&
      activePageIndex == pagesLength - 1) {
    return;
  }

  if (prevUpdate != event.updateType && _currentUpdateTypeCallback != null)
    _currentUpdateTypeCallback!(event.updateType);

  if (_slidePercentCallback != null &&
      event.updateType != UpdateType.doneAnimating) {
    String hor = (event.slidePercentHor * 100).toStringAsExponential(2);
    String ver = (event.slidePercentVer * 100).toStringAsExponential(2);
    _slidePercentCallback!(
        double.parse(hor), (((double.parse(ver)) * 100) / 100));
  }

  prevUpdate = event.updateType;

  //if the user is dragging then
  if (event.updateType == UpdateType.dragging) {
    slideDirection = event.direction;
    slidePercentHor = event.slidePercentHor;
    slidePercentVer = event.slidePercentVer;

    // making pages to be in loop
    nextPageIndex = activePageIndex;
    if (enableLoop) {
      //conditions on slide direction
      if (slideDirection == SlideDirection.leftToRight) {
        nextPageIndex = activePageIndex - 1;
      } else if (slideDirection == SlideDirection.rightToLeft) {
        nextPageIndex = activePageIndex + 1;
      }

      if (nextPageIndex > pagesLength - 1) {
        nextPageIndex = 0;
      } else if (nextPageIndex < 0) {
        nextPageIndex = pagesLength - 1;
      }
      return;
    }

    //conditions on slide direction
    if (slideDirection == SlideDirection.leftToRight &&
        activePageIndex != 0) {
      nextPageIndex = activePageIndex - 1;
    } else if (slideDirection == SlideDirection.rightToLeft &&
        activePageIndex != pagesLength - 1) {
      nextPageIndex = activePageIndex + 1;
    }
    return;
  }
  //if the user has done dragging
  else if (event.updateType == UpdateType.doneDragging) {
    // slidepercent > 0.2 so that it wont reveal itself unless this condition is true
    if (slidePercentHor > 0.2) {
      isAnimating = true; // Page started to animate

      animatedPageDragger = AnimatedPageDragger(
        slideUpdateStream: this,
        slideDirection: slideDirection,
        transitionGoal: TransitionGoal.open,
        slidePercentHor: slidePercentHor,
        slidePercentVer: slidePercentVer,
        vsync: singleTickerProviderStateMixin,
      );
    } else {
      animatedPageDragger = AnimatedPageDragger(
        slideUpdateStream: this,
        slideDirection: slideDirection,
        transitionGoal: TransitionGoal.close,
        slidePercentHor: slidePercentHor,
        slidePercentVer: slidePercentVer,
        vsync: singleTickerProviderStateMixin,
      );

      nextPageIndex = activePageIndex;
    }
    //Run the animation
    animatedPageDragger.run();
    return;
  }
  //when animating
  else if (event.updateType == UpdateType.animating) {
    slideDirection = event.direction;
    slidePercentHor = event.slidePercentHor;
    slidePercentVer = event.slidePercentVer;
    return;
  }

  //done animating
  if (_onPageChangeCallback != null) {
    _onPageChangeCallback!(nextPageIndex);
  }
  activePageIndex = nextPageIndex;
  slideDirection = SlideDirection.rightToLeft;
  slidePercentHor = 0.00;
  slidePercentVer = positionSlideIcon;
  nextPageIndex = activePageIndex;

  if (enableLoop) {
    //conditions on slide direction
    if (slideDirection == SlideDirection.leftToRight) {
      nextPageIndex = activePageIndex - 1;
    } else if (slideDirection == SlideDirection.rightToLeft) {
      nextPageIndex = activePageIndex + 1;
    }

    if (nextPageIndex > pagesLength - 1) {
      nextPageIndex = 0;
    } else if (nextPageIndex < 0) {
      nextPageIndex = pagesLength - 1;
    }
  } else {
    if (slideDirection == SlideDirection.leftToRight &&
        activePageIndex != 0) {
      nextPageIndex = activePageIndex - 1;
    } else if (slideDirection == SlideDirection.rightToLeft &&
        activePageIndex != pagesLength - 1) {
      nextPageIndex = activePageIndex + 1;
    }
  }

  isAnimating = false; // Page stopped animating
  return;
}