Open sohailmahmud opened 3 years ago
One solution to this is to create an autoplay. Example for 3 images. late PageController? _pageController = PageController(); var _timer;
@override void initState() { super.initState(); startBanner(); }
void startBanner() { WidgetsBinding.instance.addPostFrameCallback((_) { _pageController = PageController( viewportFraction: 0.9, initialPage: 0, );
_timer = Timer.periodic(
const Duration(seconds: 5),
(Timer timer) {
_pageController?.nextPage(
duration: const Duration(milliseconds: 350),
curve: Curves.easeIn,
);
if (_pageController?.page == 2.0) {
_pageController?.jumpToPage(0);
}
},
);
});
}
@override void dispose() { super.dispose(); _timer.cancel(); }
Hello, I might as well answer this:
Switch to stateful
Code this: `@override void initState() { super.initState(); _pageController = PageController( viewportFraction: 0.9, initialPage: 0, ); _timer = Timer.periodic( const Duration(seconds: 5), // ignore: prefer-extracting-callbacks (Timer timer) { _pageController.nextPage( duration: const Duration(milliseconds: 350), curve: Curves.easeIn, ); }, ); }
@override void dispose() { super.dispose(); _timer.cancel(); }`
Add the pageController parameter to your Carousel