appinioGmbH / flutter_packages

Dart and Flutter plugins/packages used and maintained by @appinioGmbH
187 stars 214 forks source link

Swipe scrollable child keep scroll offset #22

Closed eloipeloux closed 2 years ago

eloipeloux commented 2 years ago

Hi there,

I've been trying this package and managed to use it on my own project (lovely), but I have an issue with my scrollable elements ... In fact, when I scroll on the first element of my List and swipe it (left or right, it doesn't matter), the very next item has the exact same scroll position. I've tried to force the position on my child element :

child: SingleChildScrollView( controller: ScrollController( keepScrollOffset: false, initialScrollOffset: widget.scrollPosition // = 0 ), physics: const ClampingScrollPhysics(), child: Column(...)

I've googled many things and nothing seems to fit my problem. Any help would be very appreciated.

I can add more code if needed for further researches.

Kind regards :)

bilalhamud commented 2 years ago

Hi @eloipeloux,

It would be very helpful if you can share your code. Thanks :)

eloipeloux commented 2 years ago

Thanks for your reactivity @bilalhammoud ! Here's my public repository, feel free to have a look : https://github.com/eloipeloux/walkhome

P.S. : I'm brand new to dart, I began 5 days ago, so any feedback is good ;)

eloipeloux commented 2 years ago

Hi @eloipeloux,

It would be very helpful if you can share your code. Thanks :)

Hello @bilalhammoud, I'm still blocked on this so been working on other features :( Do you have any idea ?

Thanks !

bilalhamud commented 2 years ago

So the problem is that you are using the same widget/component.

List<AdCard> cards = [
      AdCard(ad: ad),
      AdCard(ad: ad),
      AdCard(ad: ad),
      AdCard(ad: ad),
      AdCard(ad: ad),
    ];

What you need to do is just to give unique IDs/Keys as followed

List<AdCard> cards = [
      AdCard(key: const Key('000'), ad: ad),
      AdCard(key: const Key('001'), ad: ad),
      AdCard(key: const Key('002'), ad: ad),
      AdCard(key: const Key('003'), ad: ad),
      AdCard(key: const Key('004'), ad: ad),
    ];

This should solve it :)

eloipeloux commented 2 years ago

Damn you're a life savior !!

Thanks for your time/help man !

Cheers 🎉