serenader2014 / flutter_carousel_slider

A flutter carousel widget, support infinite scroll, and custom child widget.
https://pub.dev/packages/carousel_slider
MIT License
1.6k stars 582 forks source link

PageStorage.of() was called with a context that does not contain a PageStorage widget. #441

Open SeakyLuo opened 5 months ago

SeakyLuo commented 5 months ago

`The following assertion was thrown building AnimatedBuilder(listenable: PageController#2a859(one client, offset 0.0), dirty, state: _AnimatedState#6b52d): PageStorage.of() was called with a context that does not contain a PageStorage widget.

No PageStorage widget ancestor could be found starting from the context that was passed to PageStorage.of(). This can happen because you are using a widget that looks for a PageStorage ancestor, but no such ancestor exists. The context used was: Scrollable(axisDirection: right, physics: _ForceImplicitScrollPhysics -> PageScrollPhysics -> ClampingScrollPhysics -> RangeMaintainingScrollPhysics, restorationId: null, dependencies: [MediaQuery, UnmanagedRestorationScope, _InheritedTheme, _LocalizationsScope-[GlobalKey#1c508]], state: ScrollableState#572d8(position: _PagePosition#22c88(offset: 0.0, range: null..null, viewport: 371.4, ScrollableState, _ForceImplicitScrollPhysics -> PageScrollPhysics -> ClampingScrollPhysics -> RangeMaintainingScrollPhysics -> ClampingScrollPhysics -> RangeMaintainingScrollPhysics, IdleScrollActivity#c06c9, ScrollDirection.idle), effective physics: _ForceImplicitScrollPhysics -> PageScrollPhysics -> ClampingScrollPhysics -> RangeMaintainingScrollPhysics -> ClampingScrollPhysics -> RangeMaintainingScrollPhysics)) The relevant error-causing widget was: CarouselSlider CarouselSlider:file:///C:/Users/luoki/Desktop/Projects/Flutter/world-street-flutter/lib/pages/shopping_bag/shopping_bag_dialog.dart:51:29 When the exception was thrown, this was the stack:

0 PageStorage.of. (package:flutter/src/widgets/page_storage.dart:220:9)

1 PageStorage.of (package:flutter/src/widgets/page_storage.dart:232:6)

2 CarouselSliderState.build.. (package:carousel_slider/carousel_slider.dart:358:33)

`

My usage:

Widget _buildProductGallery(){ return Container( height: galleryHeight, color: Colors.transparent, padding: const EdgeInsets.only(top: Global.statusBarHeight + 20, bottom: 20, left: 20, right: 20), child: CarouselSlider.builder( options: CarouselOptions(height: 260, enlargeCenterPage: true, enableInfiniteScroll: false, initialPage: 0), itemCount: widget.product.pictures.length, itemBuilder: (context, itemIndex, pageViewIndex) { return ClipRRect( borderRadius: const BorderRadius.all(Radius.circular(10)), child: CachedNetworkImage(imageUrl: widget.product.pictures[itemIndex], width: 260, height: 260, fit: BoxFit.cover) ); } ), ); }

orliu commented 1 month ago

I got the same issue