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

onScrolled called after onPageChanged #151

Open sourcecodeit opened 4 years ago

sourcecodeit commented 4 years ago

Hi, first of all thank you for this package, it's simply awesome 👍

I have a problem with events. I'm using a carousel providing my own builder. What I'm trying to achieve is starting an animation when the page is changed and reverse the animation when the slider is scrolling. So the user sees a nice animation every time it changes page.

The problem is that the event onScrolled is called also after onPageChanged so I don't know when the scroll really ends.

My code:

onPageChanged: (index, reason) { print("page changed"); _animController.forward(); setState(() { buttonsHidden = false; }); }, onScrolled: (value) { print("on scrolled"); if(! buttonsHidden) { print("hide"); _animController.reverse(); setState(() { buttonsHidden = true; }); } }

The output:

I/flutter (29099): on scrolled I/flutter (29099): on scrolled I/chatty (29099): uid=10150(com.greentreelabs.studio) Thread-3 identical 3 lines I/flutter (29099): on scrolled I/flutter (29099): page changed I/flutter (29099): on scrolled <<<<<<< WHY? I/flutter (29099): hide I/flutter (29099): on scrolled

You can see a video of the issue: https://youtu.be/eEXpYy6Ap4o

sourcecodeit commented 4 years ago

Got it, page changes when the slide scroll more than 50% of its width:

image

It would be great if we could also have an event to know when actually the slider stops. Maybe I can check for the value of the scroll, I can fire my logic when user has slided more than 95% or so.

n4lexeev commented 4 years ago

ye got same problem, slide animation breaks when data is updated