flutter_carousel_slider
flutter_carousel_slider copied to clipboard
Get timer error
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;
}
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