Repository navigation
Odd scroll behavior and occasional asserts with trackpad #149999
Copy link
Copy link
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: desktopRunning on desktopRunning on desktopa: error messageError messages from the Flutter frameworkError messages from the Flutter frameworkc: regressionIt was better in the past than it is nowIt was better in the past than it is nowf: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 3.23Found to occur in 3.23Found to occur in 3.23frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Steps to reproduce
- Run flutter create and replace main.dart with the provided code sample.
- Run on macOS
- 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
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]Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: desktopRunning on desktopRunning on desktopa: error messageError messages from the Flutter frameworkError messages from the Flutter frameworkc: regressionIt was better in the past than it is nowIt was better in the past than it is nowf: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 3.23Found to occur in 3.23Found to occur in 3.23frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team


Activity
[-]Odd scroll behavior with trackpad[/-][+]Odd scroll behavior and occasional asserts with trackpad[/+]HansMuller commentedon Jun 10, 2024
@darshankawar - if you have a chance to check to see if this issue was introduced by #146654, we'd appreciate it.
huycozy commentedon Jun 11, 2024
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 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!HansMuller commentedon Jun 11, 2024
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:I believe that we only want to clamp
newPositionon 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 manythumbFoomethods, even though those drag gestures did not originate with a press on the scrollbar thumb.11 remaining items
tgucio commentedon Jun 14, 2024
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:

Trying to put together minimal repro code that would behave the same after hot reload but this is proving difficult.
tgucio commentedon Jun 17, 2024
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:
VerticalDragGestureRecognizerVerticalDragGestureRecognizer+ 2x_VerticalThumbDragGestureRecognizerThis in turn is because the content of the document painter is updated asynchronously using a method similar to updating
EditableTextvia itsTextEditingControllervalue. As a result the scroll extent changes but inRawScrollbarStatewe don't update the recognizers first created using the_gesturesgetter 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?
HansMuller commentedon Jun 17, 2024
Corrected "scroll direction is reversed, scrolling is too fast", investigating the reload problem
HansMuller commentedon Jun 17, 2024
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
_gesturesgetter in scrollbar.dart only returns one).Could you create a test case that demonstrates the problem in terms of incorrect scrolling behavior?
Yes, that's the way it has always worked.
tgucio commentedon Jun 17, 2024
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_gesturesgetter 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:_gesturesgetter returns an empty map due to_canHandleScrollGestures()condition_effectiveScrollController!.position.maxScrollExtent > 0.0-> no_VerticalThumbDragGestureRecognizeris created.EditableTextcontent is updated and is now bigger than the viewport but this metrics update notification isn't handled (see `_handleScrollMetricsNotification())._VerticalThumbDragGestureRecognizeris createdHansMuller commentedon Jun 18, 2024
#150275 updates
_handleScrollMetricsNotification(): now the scrollbar rebuilds if the value ofmetrics.maxScrollExtent > 0changes.At this point I believe I've addressed all of the issues raised here; let me know if everything works correctly for you.
tgucio commentedon Jun 20, 2024
Good stuff, thanks! Will give the PR some testing when back from leave next week.
tgucio commentedon Jun 25, 2024
@HansMuller everything's looking good - huge thanks!
Improve the behavior of scrollbar drag-scrolls triggered by the track…
Improve the behavior of scrollbar drag-scrolls triggered by the track…
github-actions commentedon Jul 11, 2024
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 -vand a minimal reproduction of the issue.