fluttercandies / flutter_scrollview_observer

A widget for observing data related to the child widgets being displayed in a ScrollView. Maintainer: @LinXunFeng
https://pub.dev/packages/scrollview_observer
MIT License
444 stars 46 forks source link

[Discussions] Application performance issue when using scrollview_observer library #98

Closed ducky-z closed 3 weeks ago

ducky-z commented 3 weeks ago

Content

I find this library quite useful, and I'm using it to scroll to a specified index. However, I’m wondering, if I have a list with, say, 10,000 items and use a SliverList, will wrapping it in a ListViewObserver reduce the app’s performance for such a large list? Specifically, will it consume significant CPU or RAM resources, since it has to listen to continuous scrolling events?

LinXunFeng commented 3 weeks ago

It will only iterate over and observe the items in the cache and display area, and if you do not implement callbacks such as onObserve and onObserveAll, it will not observe the items.

https://github.com/fluttercandies/flutter_scrollview_observer/blob/76c0310e237d22d64a127493c39cb871b51ea0ff/lib/src/common/observer_widget.dart#L311-L313

If you implement these callbacks, you can also adjust the observation frequency by setting observeIntervalForScrolling.

https://github.com/fluttercandies/flutter_scrollview_observer/blob/76c0310e237d22d64a127493c39cb871b51ea0ff/lib/src/common/observer_controller.dart#L31-L35

ducky-z commented 3 weeks ago

It will only iterate over and observe the items in the cache and display area, and if you do not implement callbacks such as onObserve and onObserveAll, it will not observe the items.

https://github.com/fluttercandies/flutter_scrollview_observer/blob/76c0310e237d22d64a127493c39cb871b51ea0ff/lib/src/common/observer_widget.dart#L311-L313

If you implement these callbacks, you can also adjust the observation frequency by setting observeIntervalForScrolling.

https://github.com/fluttercandies/flutter_scrollview_observer/blob/76c0310e237d22d64a127493c39cb871b51ea0ff/lib/src/common/observer_controller.dart#L31-L35

How can I customize "observeIntervalForScrolling"? I don't see in the documentation how to use it

LinXunFeng commented 3 weeks ago

How can I customize "observeIntervalForScrolling"? I don't see in the documentation how to use it

Oh, I find time to add it to the wiki. you can set it as follows.

observerController.observeIntervalForScrolling = Duration(milliseconds: 500);
ducky-z commented 3 weeks ago

Thank you very much.