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
438 stars 47 forks source link

[Bug report] jumpTo is too slow #79

Closed IWantToKnowAboutThis closed 6 months ago

IWantToKnowAboutThis commented 6 months ago

Version

1.19.1

Platforms

Android

Device Model

Galaxy s9+

flutter info

• Engine revision e76c956498
    • Dart version 3.3.3
    • DevTools version 2.31.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Android\SDK                                             
    • Platform android-34, build-tools 34.0.0                                   
    • Java binary at: C:\Android\Studio\jbr\bin\java                     
    • Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874)
    • All Android licenses accepted.                                     

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[!] Visual Studio - develop Windows apps (Visual Studio Community 2019 16.11.18)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.32802.440
    • Windows 10 SDK version 10.0.16299.0
    X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components:
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK

[√] Android Studio (version 2023.2)
    • Android Studio at C:\Android\Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874)

[√] Connected device (4 available)
    • SM G965F (mobile) • 1b9414152b027ece • android-arm64  • Android 13 (API 33)
    • Windows (desktop) • windows          • windows-x64    • Microsoft Windows [Version 10.0.19045.4291]
    • Chrome (web)      • chrome           • web-javascript • Google Chrome 124.0.6367.63
    • Edge (web)        • edge             • web-javascript • Microsoft Edge 124.0.2478.67

[√] Network resources
    • All expected network resources are available.

How to reproduce?

observerController.jumpTo(index: 450);

The jumpTo function is too slow. It's like animateTo. In my case, My app has the ability to search for messages. Sometimes I have to go directly from index 0 to 1000. But the scrolling is too slow to get to the wanted index.

I want it to scroll to position immediately, such as scrollable_positioned_list or super_sliver_list. It's better to have alignment. Is it possible?

Thank you.

Logs

No response

Example code (optional)

observerController.jumpTo(index: 450);

Contact

No response

LinXunFeng commented 6 months ago

No, unless the height of your item is fixed.

observerController.jumpTo(index: 450, isFixedHeight: true); 

Releated issue: https://github.com/fluttercandies/flutter_scrollview_observer/issues/5

IWantToKnowAboutThis commented 6 months ago

My app is chat app. Of course, each item is different in height.

IWantToKnowAboutThis commented 6 months ago

In the _handleScrollToIndex function, nextPageOffsetRectified is looking for it one by one, is there a way to go at once?

LinXunFeng commented 6 months ago

Only when the target item is rendered can this package calculate the corresponding offset.

Without scrolling, it is impossible for the ListView to render the item with index 450 unless the cacheExtent is double.maxFinite. However, if the cacheExtent is set to double. maxFinite, an extremely large number of items will be rendered at once. This behavior is undesirable in your scenario because it will affect performance.

IWantToKnowAboutThis commented 6 months ago

There's something library super_sliver_list, and I don't know if it's jumpTo after item rendering, but it's jumpToItem directly. But I need ChatObserverClampingScrollPhysics with physics like scrollview_observer. Because chat app need to that function what fix scroll position when other person sends me a chat message.

LinXunFeng commented 6 months ago

Don’t worry, scrollview_observer supports use with other third-party packages, as shown in the following code.

var scrollViewPhysics =
    physics.applyTo(ChatObserverClampingScrollPhysics(
  observer: chatObserver,
));
+ Widget resultWidget = SuperListView.builder(
  physics: chatObserver.isShrinkWrap
      ? const NeverScrollableScrollPhysics()
      : scrollViewPhysics,
  shrinkWrap: chatObserver.isShrinkWrap,
  reverse: true,
  controller: scrollController,
  itemBuilder: ((context, index) {
    return ...;
  }),
  ...,
);

resultWidget = ListViewObserver(
  controller: observerController,
  child: resultWidget,
+  customTargetRenderSliverType: (renderObj) {
+    return renderObj.runtimeType.toString() == 'RenderSuperSliverList';
+  },
);
IWantToKnowAboutThis commented 6 months ago

Oh, my God. You're a genius. Thank you