nixrajput / flutter_carousel_widget

A customizable Flutter carousel widget with infinite scrolling, auto-scrolling, pre-built indicators, expandable widgets, auto-sized child support, and enlarged center page.
https://pub.dev/packages/flutter_carousel_widget
MIT License
34 stars 20 forks source link

State null error with controller #14

Closed under3415 closed 1 year ago

under3415 commented 1 year ago

When trying to programmatically scroll on tap event, I am getting below error. Sometimes on first tap, other times it works once, then it fails on second tap.

_CastError (Null check operator used on a null value)

Error is on line 78, _state is null: final isNeedResetTimer = _state!.options.pauseAutoPlayOnManualNavigate;

This is my code snippet:

 Widget build(BuildContext context) {
    CarouselController gestureCarouselController = CarouselController();

    return GestureDetector(
        onTap: () {
          gestureCarouselController.nextPage(
              duration: const Duration(milliseconds: 300),
              curve: Curves.linear);
        },
        child: FlutterCarousel(
          options: CarouselOptions(
              controller: gestureCarouselController,
              showIndicator: false,
etc...
under3415 commented 1 year ago

My bad, had to move controller declaration out of the build method