flutter_carousel_slider icon indicating copy to clipboard operation
flutter_carousel_slider copied to clipboard

Get timer error

Open muhammadkamel opened this issue 2 years ago • 1 comments

I am using the latest version...

E/flutter (21223): At this point the state of the widget's element tree is no longer stable. E/flutter (21223): To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.

Library get timer method. Timer? getTimer() { return widget.options.autoPlay ? Timer.periodic(widget.options.autoPlayInterval, (_) { final route = ModalRoute.of(context); if (route?.isCurrent == false) { return; }

        CarouselPageChangedReason previousReason = mode;
        changeMode(CarouselPageChangedReason.timed);
        int nextPage = carouselState!.pageController!.page!.round() + 1;
        int itemCount = widget.itemCount ?? widget.items!.length;

        if (nextPage >= itemCount &&
            widget.options.enableInfiniteScroll == false) {
          if (widget.options.pauseAutoPlayInFiniteScroll) {
            clearTimer();
            return;
          }
          nextPage = 0;
        }

        carouselState!.pageController!
            .animateToPage(nextPage,
                duration: widget.options.autoPlayAnimationDuration,
                curve: widget.options.autoPlayCurve)
            .then((_) => changeMode(previousReason));
      })
    : null;

}

muhammadkamel avatar Jun 29 '22 12:06 muhammadkamel

int nextPage = carouselState!.pageController!.page!.round() + 1; needs an early exit

also this line looks suspicious to me, maybe move it before super.dispose();? https://github.com/serenader2014/flutter_carousel_slider/blob/f366f6437f1f1fef7b31789c3400ce03a2425dd3/lib/carousel_slider.dart#L262

kaipo-hu avatar Jul 12 '22 09:07 kaipo-hu