Repository navigation
Animation stops when scrolling #11433
Copy link
Copy link
Closed
Labels
a: animationAnimation APIsAnimation APIsc: crashStack traces logged to the consoleStack traces logged to the consolef: gesturesflutter/packages/flutter/gestures repository.flutter/packages/flutter/gestures repository.f: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.
Milestone
Description
Steps to Reproduce
I am creating NumberPicker which is a ListView inside a Dialog.
Right now after opening a dialog and scrolling few times I get an error and then the scrolling just freezes.
The reason is calling intScrollController.animateTo method.
In the attached gif you can see that at first I can scroll freely but at some point the scroll freezes and I get a lot of this:
I/flutter ( 3471): Another exception was thrown: 'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 414: '_hold == null || _drag == null': is not true.
Code
Widget _intListView(ThemeData themeData) {
final TextStyle style = themeData.textTheme.body1;
return new NotificationListener(
child: new Container(
height: _listViewHeight,
width: log(widget.maxIntValue).floorToDouble() * 20,
child: new ListView.builder(
controller: intScrollController,
itemExtent: _itemExtent,
itemCount: widget.maxIntValue - widget.minIntValue + 3,
itemBuilder: (BuildContext context, int index) {
final int value = widget.minIntValue + index - 1;
final TextStyle itemStyle = value == selectedIntValue
? themeData.textTheme.headline
.copyWith(color: themeData.accentColor)
: style;
bool isExtra = index == 0 ||
index == widget.maxIntValue - widget.minIntValue + 2;
return isExtra
? new Container()
: new Center(
child: new Text(value.toString(), style: itemStyle),
);
},
),
),
onNotification: (notification) {
if (notification is ScrollNotification) {
if (notification is UserScrollNotification && notification.direction == ScrollDirection.idle) {
intScrollController.animateTo(
(selectedIntValue - widget.minIntValue) * _itemExtent,
duration: new Duration(seconds: 1),
curve: new ElasticOutCurve());
} else {
//calculate
int intIndexOfMiddleElement =
(notification.metrics.pixels + _listViewHeight / 2) ~/
_itemExtent;
int intValueInTheMiddle =
widget.minIntValue + intIndexOfMiddleElement - 1;
if (intValueInTheMiddle != selectedIntValue) {
setState(() => selectedIntValue = intValueInTheMiddle);
}
}
}
return true;
},
);
}
Logs
Error message:
I/flutter (20929): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter (20929): The following assertion was thrown while handling a gesture:
I/flutter (20929): 'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 409 pos 12: '_hold == null':
I/flutter (20929): is not true.
I/flutter (20929): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (20929): more information in this error message to help you determine and fix the underlying cause.
I/flutter (20929): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (20929): https://github.com/flutter/flutter/issues/new
I/flutter (20929): When the exception was thrown, this was the stack:
I/flutter (20929): #2 ScrollableState._handleDragStart (package:flutter/src/widgets/scrollable.dart:409:12)
I/flutter (20929): #3 DragGestureRecognizer.acceptGesture.<anonymous closure> (package:flutter/src/gestures/monodrag.dart:156:54)
I/flutter (20929): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:71:24)
I/flutter (20929): #5 DragGestureRecognizer.acceptGesture (package:flutter/src/gestures/monodrag.dart:156:9)
I/flutter (20929): #6 GestureArenaManager._resolveByDefault (package:flutter/src/gestures/arena.dart:171:25)
I/flutter (20929): #7 GestureArenaManager._tryToResolveArena.<anonymous closure> (package:flutter/src/gestures/arena.dart:178:31)
I/flutter (20929): (elided 4 frames from class _AssertionError and package dart:async)
I/flutter (20929): Handler: onStart
I/flutter (20929): Recognizer:
I/flutter (20929): VerticalDragGestureRecognizer#3b7b5
I/flutter (20929): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (20929): Another exception was thrown: 'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 414 pos 12: '_hold == null || _drag == null': is not true.
I/flutter (20929): Another exception was thrown: 'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 414 pos 12: '_hold == null || _drag == null': is not true.
I/flutter (20929): Another exception was thrown: 'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 414 pos 12: '_hold == null || _drag == null': is not true.
I/flutter (20929): Another exception was thrown: 'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 414 pos 12: '_hold == null || _drag == null': is not true.
I/flutter (20929): Another exception was thrown: 'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 414 pos 12: '_hold == null || _drag == null': is not true.
I/flutter (20929): Another exception was thrown: 'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 414 pos 12: '_hold == null || _drag == null': is not true.
I/flutter (20929): Another exception was thrown: 'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 414 pos 12: '_hold == null || _drag == null': is not true.
I/flutter (20929): Another exception was thrown: 'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 414 pos 12: '_hold == null || _drag == null': is not true.
I/flutter (20929): Another exception was thrown: 'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 414 pos 12: '_hold == null || _drag == null': is not true.
I/flutter (20929): Another exception was thrown: 'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 420 pos 12: '_hold == null || _drag == null': is not true.
Flutter Analyze
Analyzing /home/marcinus/dev/numberpicker...
No issues found!
Ran in 6.3s
Flutter Doctor
[✓] Flutter (on Linux, locale en_US.UTF-8, channel alpha)
• Flutter at /home/marcinus/flutter
• Framework revision d36e2f6191 (5 weeks ago), 2017-06-21 15:09:10 -0700
• Engine revision b0dee695ec
• Tools Dart version 1.24.0-dev.6.7
[✓] Android toolchain - develop for Android devices (Android SDK 25.0.3)
• Android SDK at /home/marcinus/Android/Sdk
• Platform android-25, build-tools 25.0.3
• Java binary at: /home/marcinus/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
[✓] Android Studio (version 2.3)
• Android Studio at /home/marcinus/android-studio
• Gradle version 3.2
• Java version OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
[✓] IntelliJ IDEA Ultimate Edition (version 2017.2)
• Flutter plugin version 15.2
• Dart plugin version 172.3317.48
[✓] Connected devices
• ALE L21 • W3D7N16C16019415 • android-arm • Android 6.0 (API 23)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
a: animationAnimation APIsAnimation APIsc: crashStack traces logged to the consoleStack traces logged to the consolef: gesturesflutter/packages/flutter/gestures repository.flutter/packages/flutter/gestures repository.f: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.

Activity
tresheffron commentedon May 14, 2019
I have very similar code and this is happening to me as well. It doesn't happen 100% of the time, but there is a sequence of holding+dragging in the middle of a ballistic event that triggers the error.
Pressing on the listview stops the BallisticScrollActivity. This ends the scrolling and dispatches a UserScrollNotification that is Idle with a HoldScrollActivity. That (like in MarcinusX's code) indicates the animateTo should run to center the closest item in the list.
I've added some print outputs to trace the code, but it isn't explaining to me why it's happening. Some parts of the trace have been snipped (...) where it is the same output repeated.
The trace shows that when the animateTo is called, a DrivenScrollActivity replaces the HoldScrollActivity. I bracketed a call to activity.dispose() just before the error, and that trace seems to indicate that the HoldScrollActivity is disposed of, setting the _hold to null in
Scrollable. Yet, in the very next call to _handleDragStart, _hold is not null. In a similar sequence of events further up the trace, it works fine.Logs
codeis from my app inside a NotificationListener.newActivityis the activity inbound to ScrollPosition._activityis the existing activity that is being replaced.The user interaction is to hold the current item in the list, drag partially to get to the next item in the list (causing ballistic activity), then in the midst of the ballistic activity, hold and drag again.
It took a couple of tries to cause the error. The first sets of logs show a successful sequence of events.
Of note: the error only occurs (that I've seen) when the HoldScrollActivity interrupts a BallisticScrollActivity. In the successful sequences, my attempts to interrupt the activity did not cause a BallisticScrollActivity (or was not in the midst of one) and thus no error.
The only work-around seems to be to check to ensure that _scrollController.position.activity isn't a HoldScrollActivity when the UserScrollNotification is ScrollDirection.idle. If it is, then don't invoke the animateTo. This isn't ideal though as position's
activityis only exposed for testing purposes.Flutter Doctor
Piinks commentedon Jul 2, 2019
This looks to be related to #14452
goderbauer commentedon Aug 12, 2019
Dupe of #14452.
github-actions commentedon Aug 28, 2021
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.