quire-io / scroll-to-index

scroll to index with fixed/variable row height inside Flutter scrollable widget
MIT License
511 stars 104 forks source link

Offset scrollToIndex ? #32

Closed HugoHeneault closed 3 years ago

HugoHeneault commented 3 years ago

Hi there,

Nice plugin 👏

I would like to scroll to an item and use an offset to be more precise.

In my case I have a nice-looking padding on my scroll container 👍 image

But when I scrollToIndex I don't have a way to ask him to scroll 20px before the item, making it looking a bit stuck on the left :

image

Is there a way or how would you do it if we have to implement it (I can help)

Thanks !

jerrywell commented 3 years ago

You can give a viewport boundary for it. see https://github.com/quire-io/scroll-to-index/blob/master/example/lib/main.dart#L47.

HugoHeneault commented 3 years ago

Thanks @jerrywell for your fast answer!

I used

viewPortBoundaryGetter: () => Rect.fromLTRB(20, 0, 0, 0),
        axis: Axis.horizontal)

and it worked great!

It should be more explicit that viewPortBoundaryGetter must be used with axis to get the left boundary. By default the beginGetter is the top one if we don't provide an axis parameter.