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

PageStorage Error When Use With Hero Widget #393

Closed baranngungor closed 1 year ago

baranngungor commented 1 year ago

I'm getting error after upgrade Flutter 3.7.0. I'm using CarouselSlider With Hero Widget, it wasn't get error but now i see this error until Hero animation finish. My Code and error that i see:

Hero( tag: "${widget.heroTag}", child: CarouselSlider( options: CarouselOptions( height: context.height * 0.45, aspectRatio: 1, enlargeCenterPage: true, viewportFraction: 0.9, onPageChanged: (index, reason) { setState(() { currentPhotoIndex = index; }); }, ), items: widget.productOption?.images! .map((item) => Center( child: CachedImage(url: item?.url?.big))) .toList(), ), ),

════════ Exception caught by widgets library ═══════════════════════════════════ PageStorage.of() was called with a context that does not contain a PageStorage widget. The relevant error-causing widget was CarouselSlider

IMG_D2BA3DC47DF2-1

Tameflame commented 1 year ago

@baranngungor How did you solve this? I got this exact issue today after upgrading flutter

baranngungor commented 1 year ago

@Tameflame I couldn't solve but other persons from another platform said "this is not an issue with the carousel but with how heros and inheritedwidgets work together" and "you move your call to of(context) to outside of the hero, then the value should persist during the hero flight.". I couldn't undestand but i think it doesnt about this plugin and i closed. But i'll reopen because i couldn't solve my problem and i'm not alone on this issue.

Tameflame commented 1 year ago

@baranngungor I managed to fix it: ctrl+click on that carousel_slider.dart import statement to go into the package's source code, and then modify line 358 from PageStorage.of(storageContext) to PageStorage.maybeOf(storageContext)

Simple change and it works for me.

baranngungor commented 1 year ago

@Tameflame It didn't work for me.

MWright55 commented 1 year ago

Has any progress been made on this issue? Any new things to try?

MWright55 commented 1 year ago

@Tameflame It didn't work for me.

Any available work around or way to resolve the issue?

vanomak commented 1 year ago

Just wrap the child of the Hero with PageStorage

baranngungor commented 1 year ago

@vanomak it worked for me thanks.

MohammedSalehelShazly commented 1 month ago

It was resolved when I wrapped the Image widget with the Hero Widget directly. When an error occurred, I wrapped the CarouselSlider Widget with the Hero Widget.