flutter_carousel_slider icon indicating copy to clipboard operation
flutter_carousel_slider copied to clipboard

Unhandled Exception: Null check operator used on a null value

Open AmirHosseinBaderan opened this issue 10 months ago • 1 comments

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.

AmirHosseinBaderan avatar Apr 10 '24 14:04 AmirHosseinBaderan

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();

jonneroni avatar Apr 25 '24 11:04 jonneroni