Skip to content

Odd scroll behavior and occasional asserts with trackpad #149999

Closed

Description

@tgucio

Steps to reproduce

  1. Run flutter create and replace main.dart with the provided code sample.
  2. Run on macOS
  3. Do a scroll gesture over the ListView using the trackpad

Expected results

Smooth scroll with bouncing overscroll effect
Can reverse scroll direction without releasing double tap

Actual results

Scroll appears to jump erratically, no overscroll effect
When at viewport top, after trying to scroll up further cannot reverse scroll down by reversing the swipe direction

Current master:
master

After reverting to 529a4d2:
revert

Occasionally the following asserts are seen:

Logs
════════ Exception caught by scheduler library ═════════════════════════════════
The following assertion was thrown during a scheduler callback:
'package:flutter/src/animation/animation_controller.dart': Failed assertion: line 898 pos 12: 'elapsedInSeconds >= 0.0': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

When the exception was thrown, this was the stack:
#2      AnimationController._tick (package:flutter/src/animation/animation_controller.dart:898:12)
#3      Ticker._tick (package:flutter/src/scheduler/ticker.dart:258:12)
#4      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1392:15)
#5      SchedulerBinding.handleBeginFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:1235:11)
#6      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:633:13)
#7      SchedulerBinding.handleBeginFrame (package:flutter/src/scheduler/binding.dart:1233:17)
#8      SchedulerBinding._handleBeginFrame (package:flutter/src/scheduler/binding.dart:1150:5)
#9      _invoke1 (dart:ui/hooks.dart:328:13)
#10     PlatformDispatcher._beginFrame (dart:ui/platform_dispatcher.dart:397:5)
#11     _beginFrame (dart:ui/hooks.dart:272:31)
(elided 2 frames from class _AssertionError)

This exception was thrown in the context of a scheduler callback. When the scheduler callback was _registered_ (as opposed to when the exception was thrown), this was the stack:
#2      SchedulerBinding.scheduleFrameCallback (package:flutter/src/scheduler/binding.dart:606:49)
#3      Ticker.scheduleTick (package:flutter/src/scheduler/ticker.dart:274:46)
#4      Ticker.start (package:flutter/src/scheduler/ticker.dart:180:7)
#5      AnimationController._startSimulation (package:flutter/src/animation/animation_controller.dart:818:42)
#6      AnimationController._animateToInternal (package:flutter/src/animation/animation_controller.dart:689:12)
#7      AnimationController.forward (package:flutter/src/animation/animation_controller.dart:498:12)
#8      new InkHighlight (package:flutter/src/material/ink_highlight.dart:60:9)
#9      _InkResponseState.updateHighlight (package:flutter/src/material/ink_well.dart:992:29)
#10     _InkResponseState.handleHoverChange (package:flutter/src/material/ink_well.dart:1269:5)
#11     _InkResponseState.handleMouseEnter (package:flutter/src/material/ink_well.dart:1257:7)
#12     MouseTracker._handleDeviceUpdateMouseEvents (package:flutter/src/rendering/mouse_tracker.dart:423:29)
#13     MouseTracker._handleDeviceUpdate (package:flutter/src/rendering/mouse_tracker.dart:277:5)
#14     MouseTracker.updateAllDevices.<anonymous closure> (package:flutter/src/rendering/mouse_tracker.dart:373:9)
#15     MouseTracker._deviceUpdatePhase (package:flutter/src/rendering/mouse_tracker.dart:205:9)
#16     MouseTracker.updateAllDevices (package:flutter/src/rendering/mouse_tracker.dart:367:5)
#17     RendererBinding._scheduleMouseTrackerUpdate.<anonymous closure> (package:flutter/src/rendering/binding.dart:485:22)
#18     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1392:15)
#19     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1326:11)
#20     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1171:5)
#21     _invoke (dart:ui/hooks.dart:312:13)
#22     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)
#23     _drawFrame (dart:ui/hooks.dart:283:31)
(elided 2 frames from class _FrameCallbackEntry)
════════════════════════════════════════════════════════════════════════════════

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  final ScrollController _scrollController = ScrollController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('Scroll me'),
            Expanded(
              child: Scrollbar(
                controller: _scrollController,
                child: ScrollConfiguration(
                  behavior: ScrollConfiguration.of(context).copyWith(
                    scrollbars: false,
                    physics: const BouncingScrollPhysics(),
                  ),
                  child: ListView(
                    controller: _scrollController,
                    children: List<ListTile>.generate(50, (index) => ListTile(title: Text('Tile $index'), onTap: () => print('tap! $index'))),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[Paste your output here]

Activity

  1. changed the title [-]Odd scroll behavior with trackpad[/-] [+]Odd scroll behavior and occasional asserts with trackpad[/+] on Jun 10, 2024
  2. HansMuller commented on Jun 10, 2024

    @HansMuller
    Contributor

    @darshankawar - if you have a chance to check to see if this issue was introduced by #146654, we'd appreciate it.

  3. added
    in triagePresently being triaged by the triage team
    on Jun 11, 2024
  4. huycozy commented on Jun 11, 2024

    @huycozy
    Member

    I can reproduce this issue on master channel; this doesn't occur on stable 3.22.2.

    I bisected this to 92f8455 which was introduced by #146654 as @HansMuller mentioned above.

    Tailed git bisect
    ➜  flutter_master git:(92f8455ff8) git bisect bad
    92f8455ff8e0850e79c0b7598352d27da4b1be18 is the first bad commit
    commit 92f8455ff8e0850e79c0b7598352d27da4b1be18
    Author: Hans Muller <[email protected]>
    Date:   Tue Jun 4 15:02:12 2024 -0700
    
        Scrollbar thumb drag gestures now produce one start and one end scroll notification (#146654)
    flutter doctor -v (stable and master)
    [✓] Flutter (Channel stable, 3.22.2, on macOS 14.1 23B74 darwin-x64, locale en-VN)
        • Flutter version 3.22.2 on channel stable at /Users/huynq/Documents/GitHub/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 761747bfc5 (31 hours ago), 2024-06-05 22:15:13 +0200
        • Engine revision edd8546116
        • Dart version 3.4.3
        • DevTools version 2.34.3
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.3)
        • Xcode at /Applications/Xcode15.3.app/Contents/Developer
        • Build 15E204a
        • CocoaPods version 1.15.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2023.3)
        • Android Studio at /Applications/Android Studio.app/Contents
        • 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
        • android-studio-dir = /Applications/Android Studio.app/
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    
    [✓] VS Code (version 1.89.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.90.0
    
    [✓] Connected device (3 available)
        • iPhone (mobile) • d9a94afe2b649fef56ba0bfeb052f0f2a7dae95e • ios            • iOS 15.8 19H370
        • macOS (desktop) • macos                                    • darwin-x64     • macOS 14.1 23B74 darwin-x64
        • Chrome (web)    • chrome                                   • web-javascript • Google Chrome 125.0.6422.142
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    [!] Flutter (Channel master, 3.23.0-13.0.pre.187, on macOS 14.1 23B74 darwin-x64, locale en-VN)
        • Flutter version 3.23.0-13.0.pre.187 on channel master at /Users/huynq/Documents/GitHub/flutter_master
        ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision f05095e0b7 (3 hours ago), 2024-06-10 17:31:08 -0700
        • Engine revision 1cdbebee19
        • Dart version 3.5.0 (build 3.5.0-236.0.dev)
        • DevTools version 2.36.0
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 15.3)
        • Xcode at /Applications/Xcode15.3.app/Contents/Developer
        • Build 15E204a
        • CocoaPods version 1.15.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2023.3)
        • Android Studio at /Applications/Android Studio.app/Contents
        • 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
        • android-studio-dir = /Applications/Android Studio.app/
        • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    
    [✓] VS Code (version 1.90.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.90.0
    
    [✓] Connected device (3 available)
        • iPhone (mobile) • d9a94afe2b649fef56ba0bfeb052f0f2a7dae95e • ios            • iOS 15.8 19H370
        • macOS (desktop) • macos                                    • darwin-x64     • macOS 14.1 23B74 darwin-x64
        • Chrome (web)    • chrome                                   • web-javascript • Google Chrome 125.0.6422.142
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
  5. added
    c: regressionIt was better in the past than it is now
    frameworkflutter/packages/flutter repository. See also f: labels.
    f: scrollingViewports, list views, slivers, etc.
    a: error messageError messages from the Flutter framework
    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 Jun 11, 2024
  6. HansMuller commented on Jun 11, 2024

    @HansMuller
    Contributor

    After applying #149925 I haven't been able to reproduce the crash however it looks like the fact that using the trackpad to drag the scrollbar doesn't cause a bounce is due to this logic from _getPrimaryDelta() in scrollbar.dart:

      // The physics may allow overscroll when actually *scrolling*, but
      // dragging on the scrollbar does not always allow us to enter overscroll.
      switch (ScrollConfiguration.of(context).getPlatform(context)) {
        case TargetPlatform.fuchsia:
        case TargetPlatform.linux:
        case TargetPlatform.macOS:
        case TargetPlatform.windows:
          newPosition = clampDouble(newPosition, position.minScrollExtent, position.maxScrollExtent);
    
        case TargetPlatform.iOS:
        case TargetPlatform.android:
          // We can only drag the scrollbar into overscroll on mobile
          // platforms, and only then if the physics allow it.
          break;
      }

    I believe that we only want to clamp newPosition on desktop platforms if the user has dragged the scrollbar thumb. Trackpad and touch-screen drags are all routed to the thumb gesture recognizer and its many thumbFoo methods, even though those drag gestures did not originate with a press on the scrollbar thumb.

  7. added
    P3Issues that are less important to the Flutter project
    on Jun 12, 2024
  8. 11 remaining items

  9. tgucio commented on Jun 14, 2024

    @tgucio
    ContributorAuthor

    Thanks - fling is back indeed. I'm still puzzled by why in our complete app none of the issues are seen right after app restart and then the behaviour changes as soon as any other UI element is hovered over or the mouse cursor leaves the window and returns to it. In the recording below I'm repeatedly doing two-finger swipe down on the trackpad, before and after moving the cursor out and back over the window:
    scroll-leave-scroll

    Trying to put together minimal repro code that would behave the same after hot reload but this is proving difficult.

  10. tgucio commented on Jun 17, 2024

    @tgucio
    ContributorAuthor

    I think I've been able to understand the reason for different behaviour right after app (re)load and after hovering outside of the app window or another UI element. It has to do with what gesture recognisers are in the arena:

    • after app load (OK trackpad scroll behaviour): VerticalDragGestureRecognizer
    • after hovering somewhere (NOK trackpad scroll behaviour): VerticalDragGestureRecognizer + 2x _VerticalThumbDragGestureRecognizer
      This in turn is because the content of the document painter is updated asynchronously using a method similar to updating EditableText via its TextEditingController value. As a result the scroll extent changes but in RawScrollbarState we don't update the recognizers first created using the _gestures getter when the scroll extent was 0.0. Sounds like we should be handling extent changes in _handleScrollNotification() to have the scrollbar widget rebuild itself.

    Submitted #150342 for this part.

    I guess another question is: if I hover the pointer over the middle of a scrollable widget (far away from the scrollbar thumb) and do a trackpad scroll gesture, should the thumb gesture recogniser really be responding?

  11. HansMuller commented on Jun 17, 2024

    @HansMuller
    Contributor

    Corrected "scroll direction is reversed, scrolling is too fast", investigating the reload problem

  12. HansMuller commented on Jun 17, 2024

    @HansMuller
    Contributor

    after hovering somewhere (NOK trackpad scroll behaviour): VerticalDragGestureRecognizer + 2x _VerticalThumbDragGestureRecognizer

    I have looked at this a bit and, for the moment, can't understand the gesture detector log messages that imply that there are 2 _VerticalThumbDragGestureRecognizer entries in the gestures list. I've done some checking and can't find any evidence that there two instances (the _gestures getter in scrollbar.dart only returns one).

    Could you create a test case that demonstrates the problem in terms of incorrect scrolling behavior?

    I guess another question is: if I hover the pointer over the middle of a scrollable widget (far away from the scrollbar thumb) and do a trackpad scroll gesture, should the thumb gesture recogniser really be responding?

    Yes, that's the way it has always worked.

  13. tgucio commented on Jun 17, 2024

    @tgucio
    ContributorAuthor

    I have looked at this a bit and, for the moment, can't understand the gesture detector log messages that imply that there are 2 _VerticalThumbDragGestureRecognizer entries in the gestures list. I've done some checking and can't find any evidence that there two instances (the _gestures getter in scrollbar.dart only returns one).

    Could you create a test case that demonstrates the problem in terms of incorrect scrolling behavior?

    The different scroll behaviour is shown in my screen recording in #150342 - "OK" is at the beginning, "NOK" is after I move the pointer to tap the app bar. Maybe "OK" is a bit of a misnomer as it's the desired ("same as before #146654") but unexpected behaviour given we should see the problems described in this issue here.

    I believe the issue described in #150342 isn't that there are 2x _VerticalThumbDragGestureRecognizers in "NOK" case but that there are no thumb recognizers at all in "OK" and so none of the issues described here show up. The reason for the lack of scrollbar thumb is that the _gestures getter returns empty the first time it's called - and then no rebuild happens despite the scroll changing extent. So from what I can tell the events would be:

    1. Widget tree is built, scrollable content is empty.
    2. Since scroll extent is 0, _gestures getter returns an empty map due to _canHandleScrollGestures() condition _effectiveScrollController!.position.maxScrollExtent > 0.0 -> no _VerticalThumbDragGestureRecognizer is created.
    3. EditableText content is updated and is now bigger than the viewport but this metrics update notification isn't handled (see `_handleScrollMetricsNotification()).
    4. Scrolling appears to behave like before Scrollbar thumb drag gestures now produce one start and one end scroll notification #146654.
    5. Tapping elsewhere or hovering outside the app window and back triggers a rebuild of the scrollbar - now _VerticalThumbDragGestureRecognizer is created
    6. Scrolling now behaves with the issues described here
  14. HansMuller commented on Jun 18, 2024

    @HansMuller
    Contributor

    #150275 updates _handleScrollMetricsNotification(): now the scrollbar rebuilds if the value of metrics.maxScrollExtent > 0 changes.

    At this point I believe I've addressed all of the issues raised here; let me know if everything works correctly for you.

  15. tgucio commented on Jun 20, 2024

    @tgucio
    ContributorAuthor

    Good stuff, thanks! Will give the PR some testing when back from leave next week.

  16. tgucio commented on Jun 25, 2024

    @tgucio
    ContributorAuthor

    @HansMuller everything's looking good - huge thanks!

  17. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jun 27, 2024
  18. github-actions commented on Jul 11, 2024

    @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.

  19. locked as resolved and limited conversation to collaborators on Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: desktopRunning on desktopa: error messageError messages from the Flutter frameworkc: regressionIt was better in the past than it is nowf: scrollingViewports, list views, slivers, etc.found in release: 3.23Found to occur in 3.23frameworkflutter/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 versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions