serenader2014 / flutter_carousel_slider

A flutter carousel widget, support infinite scroll, and custom child widget.
https://pub.dev/packages/carousel_slider
MIT License
1.55k stars 517 forks source link

Unhandled Exception: Null check operator used on a null value #437

Closed AmirHosseinBaderan closed 6 days ago

AmirHosseinBaderan commented 1 month ago

When using the functions of the next page and the previous page, we encounter this error from the controller.

I checked the controller codes and realized that the state is null. This is the reason we are encountering an error.

jonneroni commented 3 weeks ago

I think there's an issue where the controller is being reinitialized every time the build method is being executed. I found a fix to go around this by using flutter_hooks and setting the CarouselController() inside a useState variable.

final carouselController = useState(CarouselController());

and then you can use it for example like so carouselController.value.previousPage();