Skip to content

ScrollBar moves slower than the mouse when dragging it to scroll #112072

Closed

Description

@knopp

This one is bit different from #111968. It happens with current main in cases where SliverList items extents keep increasing.

Main reason for this is that ScrollBar._updateScrollPosition adjusts viewport position by using relative scroll offset. In pathological cases like this the error keeps increasing to the point where not even overdrag is enough to reach end.

I'm wondering why ScrollBar is written like that. Setting pixels to minExtent + (absoluteScrollPosition * (maxExtent - minExtent)) would alleviate this (absoluteScrollPosition being in range of 0.0-1.0). But I'm not sure how this would work with overdrag.

import 'package:flutter/material.dart';

void main() {
  runApp(const MaterialApp(
    title: 'Flutter Demo',
    home: MyHomePage(),
  ));
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          SliverToBoxAdapter(
            child: Container(
              height: 2,
              color: Colors.red,
            ),
          ),
          SliverList(
            delegate: SliverChildBuilderDelegate(
              (context, index) => Padding(
                padding: const EdgeInsets.all(10),
                child: Container(
                  color: Colors.green,
                  height: index.toDouble(),
                ),
              ),
              childCount: 1000,
            ),
          ),
          SliverToBoxAdapter(
            child: Container(
              height: 2,
              color: Colors.red,
            ),
          ),
        ],
      ),
    );
  }
}

Activity

  1. knopp commented on Sep 21, 2022

    @knopp
    MemberAuthor
  2. added
    in triagePresently being triaged by the triage team
    on Sep 22, 2022
  3. exaby73 commented on Sep 22, 2022

    @exaby73
    Member

    Hello @knopp. I cannot reproduce this issue. When scrolling multiple times, I am still able to see the red lines. Could you please provide some more details? How do I reliably reproduce this issue and which version and/or platform is this reproducible for you? Thank you.

  4. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 22, 2022
  5. knopp commented on Sep 22, 2022

    @knopp
    MemberAuthor

    Hello @knopp. I cannot reproduce this issue. When scrolling multiple times, I am still able to see the red lines. Could you please provide some more details? How do I reliably reproduce this issue and which version and/or platform is this reproducible for you? Thank you.

    Can you maximize window and retry? You should see that the scrollbar is getting further away from mouse cursor as you scroll down. If there is no space below the window you don't be able to reach the end.

  6. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 22, 2022
  7. exaby73 commented on Sep 22, 2022

    @exaby73
    Member

    Right I noticed that behavior. I have to reset my mouse multiple times to scroll fully. Posting a full triage report in a few minutes. Thanks for the information :)

  8. exaby73 commented on Sep 22, 2022

    @exaby73
    Member

    Triage Report

    Versions reproducible on

    • Stable (3.3.2)
    • Master (3.4.0-19.0.pre.442)

    Info

    Video
    Code Sample
    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MaterialApp(
        title: 'Flutter Demo',
        home: MyHomePage(),
      ));
    }
    
    class MyHomePage extends StatefulWidget {
      const MyHomePage({super.key});
    
      @override
      State<MyHomePage> createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      @override
      void initState() {
        super.initState();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: CustomScrollView(
            slivers: [
              SliverToBoxAdapter(
                child: Container(
                  height: 2,
                  color: Colors.red,
                ),
              ),
              SliverList(
                delegate: SliverChildBuilderDelegate(
                  (context, index) => Padding(
                    padding: const EdgeInsets.all(10),
                    child: Container(
                      color: Colors.green,
                      height: index.toDouble(),
                    ),
                  ),
                  childCount: 1000,
                ),
              ),
              SliverToBoxAdapter(
                child: Container(
                  height: 2,
                  color: Colors.red,
                ),
              ),
            ],
          ),
        );
      }
    }

    Flutter Doctor

    flutter doctor -v (Stable)
    [✓] Flutter (Channel stable, 3.3.2, on Microsoft Windows [Version 10.0.22000.978], locale en-US)
        • Flutter version 3.3.2 on channel stable at C:\Users\Nabeel\fvm\versions\stable
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision e3c29ec00c (8 days ago), 2022-09-14 08:46:55 -0500
        • Engine revision a4ff2c53d8
        • Dart version 2.18.1
        • DevTools version 2.15.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
        • Android SDK at C:\android-sdk
        • Platform android-33, build-tools 33.0.0
        • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
        • All Android licenses accepted.
    
    [✓] Chrome - develop for the web
        • CHROME_EXECUTABLE = C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe
    
    [✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.3.2)
        • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
        • Visual Studio Community 2022 version 17.3.32819.101
        • Windows 10 SDK version 10.0.19041.0
    
    [✓] Android Studio (version 2021.2)
        • Android Studio at C:\Program Files\Android\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 11.0.12+7-b1504.28-7817840)
    
    [✓] VS Code (version 1.71.2)
        • VS Code at C:\Users\Nabeel\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.46.0
    
    [✓] Connected device (4 available)
        • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 13 (API 33) (emulator)
        • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22000.978]
        • Chrome (web)                 • chrome        • web-javascript • unknown
        • Edge (web)                   • edge          • web-javascript • Microsoft Edge 105.0.1343.42
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    flutter doctor -v (Master)
    [✓] Flutter (Channel master, 3.4.0-19.0.pre.442, on Microsoft Windows [Version 10.0.22000.978], locale en-US)
        • Flutter version 3.4.0-19.0.pre.442 on channel master at C:\Users\Nabeel\fvm\versions\master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 463ee3d58c (83 minutes ago), 2022-09-22 07:08:23 -0400
        • Engine revision ac6cb9f244
        • Dart version 2.19.0 (build 2.19.0-228.0.dev)
        • DevTools version 2.17.0
    
    [✓] Windows Version (Installed version of Windows is version 10 or higher)
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
        • Android SDK at C:\android-sdk
        • Platform android-33, build-tools 33.0.0
        • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
        • All Android licenses accepted.
    
    [✓] Chrome - develop for the web
        • CHROME_EXECUTABLE = C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe
    
    [✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.3.2)
        • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
        • Visual Studio Community 2022 version 17.3.32819.101
        • Windows 10 SDK version 10.0.19041.0
    
    [✓] Android Studio (version 2021.2)
        • Android Studio at C:\Program Files\Android\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 11.0.12+7-b1504.28-7817840)
    
    [✓] VS Code (version 1.71.2)
        • VS Code at C:\Users\Nabeel\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.46.0
    
    [✓] Connected device (4 available)
        • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 13 (API 33) (emulator)
        • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version 10.0.22000.978]
        • Chrome (web)                 • chrome        • web-javascript • unknown
        • Edge (web)                   • edge          • web-javascript • Microsoft Edge 105.0.1343.42
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
  9. changed the title [-]Can't scroll through entire viewport using ScrollBar[/-] [+]`ScrollBar` moves slower than the mouse when dragging it to scroll[/+] on Sep 22, 2022
  10. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: scrollingViewports, list views, slivers, etc.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Sep 22, 2022
  11. added
    P2Important issues not at the top of the work list
    on Sep 22, 2022
  12. xu-baolin commented on Sep 23, 2022

    @xu-baolin
    Member

    Actually, this is a performance issue of Flutter, when dragging the bar, building the sliver items will take a lot of time and cause frame loss.

    Workaround,
    set CustomScrollView.cacheExtent to double.maxFinite can work as you want.

    CC @Piinks

  13. knopp commented on Sep 23, 2022

    @knopp
    MemberAuthor

    Actually, this is a performance issue of Flutter, when dragging the bar, building the sliver items will take a lot of time and cause frame loss.

    Workaround, set CustomScrollView.cacheExtent to double.maxFinite can work as you want.

    CC @Piinks

    That will cause Flutter to eagerly build and layout entire content of the SliverList. Currently SliverList has a problem that in order to scroll through it it needs to build and layout all items regardless of whether they are displayed, but this is not a solution. It's also a separate issue.

  14. Piinks commented on Sep 26, 2022

    @Piinks
    Contributor

    I don't think this is a scrollbar issue, it is likely more to do with the fact that when the children of the list have variable extents (like in the sample code above), Flutter estimates what the maximum extent is, and updates it as the list grows and it has more information to inform that estimate.

    For this issue, it sounds like the scrollbar should perform some version of edge scrolling, where dragging it at the edge when it has not reached the end triggers the scroll position forward.
    Or, the way we estimate the maximum scroll offset could be updated/changed/modified to allow the user to configure.

    If the later, this is the issue to follow: #97676

  15. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 26, 2022
  16. knopp commented on Sep 26, 2022

    @knopp
    MemberAuthor

    In my opinion the primary issue is that scroll position update is always relative. So the relative scrollbar movement gets translated according to current scroll extent estimation and added to scroll position. But scroll extent estimation, especially at the very beginning, is much worse than towards the end. But with current approach this is never really corrected.

    I've been playing with scrollbars a bit and I had much better experience when settings scroll position directly to pixels = minExtent + absoluteScrollPosition * (maxExtent - minExtent). That's because the further you scroll, the more accurate extent estimation would be.

    So for example towards the end, when you are at 95%, doing layout for pixels = minExtent + 0.95 * (maxExtent - minExtent) will probably update geometry with a decently accurate maxExtent.

    Repeat this couple of times (96, 97, 98, 99%) and the maxExtent should be very close to actual value.

    After that, scrolling towards the very end, at pixels = minExtent + 1.0 * (maxExtent - minExtent), you should be at the end of viewport. Without (or with minimal) edge scrolling.

  17. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 26, 2022
  18. added
    r: fixedIssue is closed as already fixed in a newer version
    on Oct 26, 2022
  19. github-actions commented on Nov 9, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  20. locked as resolved and limited conversation to collaborators on Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: desktopRunning on desktopf: scrollingViewports, list views, slivers, etc.found in release: 3.3Found to occur in 3.3found in release: 3.4Found to occur in 3.4frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions