flutter_carousel_slider
flutter_carousel_slider copied to clipboard
Unhandled Exception: Null check operator used on a null value
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.
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();