quire-io / scroll-to-index

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

Unhandled Exception: 'package:scroll_to_index/scroll_to_index.dart' #51

Closed rockingdice closed 3 years ago

rockingdice commented 3 years ago

[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: 'package:scroll_to_index/scroll_to_index.dart': Failed assertion: line 381 pos 14: '(offsetToLastState?.offset ?? 0) >= 0': ERROR: %%%%%%%%%%%%%%: 270, 235, 1.0, RevealedOffset(offset: -610.0, rect: Rect.fromLTRB(404.5, 640.0, 799.0, 672.0)), 256,257,258,259,260,261,337,338,339,340,341,342,277,278,279,345,346,347,311,312,313,314,315,316,348,349,1597,238,239,240,235,236,237,241,242,243,308,309,310,244,245,246,326,327,328,343,344,1596,331,332,333,274,275,276,320,321,322,305,306,307

I'm not quite sure why it's failed.

rockingdice commented 3 years ago

I can confirm this issue happens when the target item is not loaded when the scroll controller tries to scroll to it. The items arrangement is not a list or regular grid - I'm using a waterfall flow package:

  waterfall_flow: 3.0.1

I've recorded a video for you to demostrate it.

https://user-images.githubusercontent.com/3458134/117746416-fe5a9d80-b23e-11eb-871c-9966df79ee10.mp4

rockingdice commented 3 years ago

OK I figured it out. I think the issue is the wrong indices. I used the data id as the index instead of its real index. Because the items are not sorted by data id, the scroll controller cannot find which direction to scroll to.

So I changed the index to group index * 100000 + item index to make it ordered so the scroll controller can find it correctly.

I don't know if there's already a reminder to keep the indices ascending - It's a requirement if you want to scroll to the index correctly. If no I think you should warn the users about it.