appinioGmbH / flutter_packages

Dart and Flutter plugins/packages used and maintained by @appinioGmbH
193 stars 230 forks source link

[Feature] : Appinio Swiper preserve widget states when moving from background to foreground #267

Open JonathanKohlhas opened 7 months ago

JonathanKohlhas commented 7 months ago

Plugin name Appinio Swiper

Is your feature request related to a problem? Please describe. When Statefull Widgets move from being in the background of the swiper to being in the foreground of the swiper, they are rebuild without preserving their state. Local keys cannot be used because the foreground and background cards don't have the same parent in the widget tree. At the same time Global Keys cannot be used, because of how the background is constructed by repeating the same widget, as this leads to error because of multiple widgets with the same global key.

Describe the solution you'd like The state of the widgets should be preserved and preferably Global Keys would also be usable on card widgets, maybe a background card could be provided to the swiper that is used for every background card after the second one ? this would prevent problems with using global keys.

Additional context In my specific case the reason why recreation of the widget state is a problem is because the cards contain looping videos that restart with a noticable delay when cards move to the foreground a card is swiped away

julian-bruening commented 6 months ago

I have exactly the same use case. The noticeable delay in my case only is a flicker, albeit an annoying one, because I started to initialize the video outside the AppinioSwiper to improve the performance. But having the behaviour like described by @JonathanKohlhas would make the code cleaner and remove the flicker altogether.

Thanks in advance!