flutter_carousel_slider
flutter_carousel_slider copied to clipboard
NoSuchMethodError: The getter 'options' was called on null.
Getting the following error
E/flutter (16405): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: The getter 'options' was called on null.
E/flutter (16405): Receiver: null
E/flutter (16405): Tried calling: options
E/flutter (16405): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (16405): #1 CarouselControllerImpl.nextPage (package:carousel_slider/carousel_controller.dart:53:42)
Using this code:
Stack(
alignment: Alignment.topCenter,
fit: StackFit.loose,
children: <Widget>[
Builder(
builder: (context) {
final double height = MediaQuery.of(context).size.height;
return CarouselSlider.builder(
carouselController: carouselController,
options: CarouselOptions(
height: height,
autoPlay: false,
enlargeCenterPage: true,
viewportFraction: 1,
initialPage: 0,
),
itemCount: pages.length,
itemBuilder: (context, index) => pages[index], // final List<Widget> pages = [Foo(), Bar(), FooBar()];
);
},
),
Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(Icons.chevron_left),
onPressed: () => carouselController.previousPage(duration: Duration(milliseconds: 300), curve: Curves.linear),
),
IconButton(
icon: Icon(Icons.chevron_right),
onPressed: () => carouselController.nextPage(duration: Duration(milliseconds: 300), curve: Curves.linear),
),
],
),
),
],
)
Is there any solution about this issue?
@Selecao found an amazing solution in https://github.com/serenader2014/flutter_carousel_slider/issues/175#issuecomment-657736568_
Hello. I have done this but doesn't work still:
CarouselSlider(
items: imageSliders,
carouselController: carouselController,
options: CarouselOptions(
autoPlay: true,
autoPlayInterval: Duration(seconds: 7),
enlargeCenterPage: true,
aspectRatio: 1.5,
viewportFraction: 1.0,
onPageChanged: (index, reason) {
setState(() {
_current = index;
});
}),
),
I fix this, by adding key to Carousel Slider.
CarouselSlider(
key: ValueKey(carouselController),
carouselController: carouselController,
),