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 516 forks source link

Replacing null check operator in nextPage, previousPage with null aware operator #417

Open AhmedAbogameel opened 8 months ago

AhmedAbogameel commented 8 months ago

We faced this bug in our release

CarouselControllerImpl.nextPage
FlutterError - Null check operator used on a null value 

so i handled it by replacing all null check operator inside nextPage and previousPage functions with null aware operator

mohamed-foly commented 8 months ago

@serenader2014 Please check this

antonderevyanko commented 2 months ago

Also faced issue Null check operator used on a null value is there a solution for this problem?

nain93 commented 2 months ago

Declare final at the top and use it outside of the rendered widget

final CarouselController carouselController = CarouselController();  <- here

class CarouselDemo extends StatelessWidget {
/// CarouselController carouselController = CarouselController(); <- not here

 @override
  Widget build(BuildContext context) => Column(
    children: <Widget>[
      CarouselSlider(
        items: child,
        carouselController: carouselController,
        options: CarouselOptions(
          autoPlay: false,
          enlargeCenterPage: true,
          viewportFraction: 0.9,
          aspectRatio: 2.0,
          initialPage: 2,
        ),
      ),
      RaisedButton(
        onPressed: () => carouselController.nextPage(
            duration: Duration(milliseconds: 300), curve: Curves.linear),
        child: Text('→'),
      )
    ]
  );
}