Repository navigation
Assertion Error using CustomScrollView with CupertinoSliverNavigationBar (Flutter 3.29) #163297
Copy link
Copy link
Closed
Labels
c: crashStack traces logged to the consoleStack traces logged to the consolef: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 3.29Found to occur in 3.29Found to occur in 3.29found in release: 3.30Found to occur in 3.30Found to occur in 3.30frameworkflutter/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 onp: cupertino_uicupertino_ui package in flutter/packagescupertino_ui package in flutter/packagesr: 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 team
Description
Steps to reproduce
When scrolling on the CupertinoSliverNavigationBar, an assertion error occurs randomly. The issue arises after performing multiple scroll gestures on the navigation bar in both directions. The following assertion errors are thrown:
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 875 pos 12: '_hold == null': is not true.
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 880 pos 12: '_hold == null || _drag == null': is not true.Steps to Reproduce:
- Run the provided code.
- Scroll up or down on the navigation bar multiple times.
- Observe the assertion errors in the debug console.
- Attempt to scroll again—scrolling is now completely broken.
Code:
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),
),
home: Scaffold(
body: CustomScrollView(
slivers: [
CupertinoSliverNavigationBar(
largeTitle: Text("Example"),
),
],
),
),
);
}
}Expected results
Regardless of the scrolling movement, no errors should be thrown.
Actual results
Assertion errors occur, and the scrolling state becomes unresponsive.
Code sample
Example
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),
),
home: Scaffold(
body: CustomScrollView(
slivers: [
CupertinoSliverNavigationBar(
largeTitle: Text("Example"),
),
],
),
),
);
}
}Screenshots or Video
Screenshots / Video demonstration
413289971-3b229b1f-37b1-418d-9fbd-dc95be1ec686.mov
Logs
Logs
======== Exception caught by gesture ===============================================================
The following assertion was thrown while handling a gesture:
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 875 pos 12: '_hold == null': 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 ScrollableState._handleDragStart (package:flutter/src/widgets/scrollable.dart:875:12)
#3 DragGestureRecognizer._checkStart.<anonymous closure> (package:flutter/src/gestures/monodrag.dart:849:53)
#4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:357:24)
#5 DragGestureRecognizer._checkStart (package:flutter/src/gestures/monodrag.dart:849:7)
#6 DragGestureRecognizer._checkDrag (package:flutter/src/gestures/monodrag.dart:815:5)
#7 DragGestureRecognizer.acceptGesture (package:flutter/src/gestures/monodrag.dart:743:7)
#8 GestureArenaManager._resolveByDefault (package:flutter/src/gestures/arena.dart:275:25)
#9 GestureArenaManager._tryToResolveArena.<anonymous closure> (package:flutter/src/gestures/arena.dart:255:31)
(elided 4 frames from class _AssertionError and dart:async)
Handler: "onStart"
Recognizer: VerticalDragGestureRecognizer#42451
start behavior: start
====================================================================================================
======== Exception caught by gesture ===============================================================
The following assertion was thrown while handling a gesture:
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 880 pos 12: '_hold == null || _drag == null': 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 ScrollableState._handleDragUpdate (package:flutter/src/widgets/scrollable.dart:880:12)
#3 DragGestureRecognizer._checkUpdate.<anonymous closure> (package:flutter/src/gestures/monodrag.dart:868:55)
#4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:357:24)
#5 DragGestureRecognizer._checkUpdate (package:flutter/src/gestures/monodrag.dart:868:7)
#6 DragGestureRecognizer.handleEvent (package:flutter/src/gestures/monodrag.dart:714:11)
#7 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:97:12)
#8 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:143:9)
#9 _LinkedHashMapMixin.forEach (dart:_compact_hash:763:13)
#10 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:141:18)
#11 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:131:7)
#12 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:530:19)
#13 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:499:22)
#14 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:460:11)
#15 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:437:7)
#16 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:394:5)
#17 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:341:7)
#18 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:308:9)
#19 _invoke1 (dart:ui/hooks.dart:332:13)
#20 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:451:7)
#21 _dispatchPointerDataPacket (dart:ui/hooks.dart:267:31)
(elided 2 frames from class _AssertionError)
Handler: "onUpdate"
Recognizer: VerticalDragGestureRecognizer#42451
start behavior: start
====================================================================================================Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.29.0, on macOS 15.3 24D60 darwin-arm64, locale de-DE) [1.836ms]
• Flutter version 3.29.0 on channel stable at /Users/***
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 35c388afb5 (4 days ago), 2025-02-10 12:48:41 -0800
• Engine revision f73bfc4522
• Dart version 3.7.0
• DevTools version 2.42.2Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
c: crashStack traces logged to the consoleStack traces logged to the consolef: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 3.29Found to occur in 3.29Found to occur in 3.29found in release: 3.30Found to occur in 3.30Found to occur in 3.30frameworkflutter/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 onp: cupertino_uicupertino_ui package in flutter/packagescupertino_ui package in flutter/packagesr: 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 team
Activity
victorsanni commentedon Feb 14, 2025
#156381 (comment)
victorsanni commentedon Feb 14, 2025
The underlying issue is that under the hood we use
ScrollPosition.animateToto snap the nav bar forward or backward when partially scrolled. But if the snap is interrupted mid-animation it throws an exception. This issue explains more.bobekos commentedon Feb 15, 2025
Thanks for pointing this out. How should we proceed here? I think there is a difference between an error caused by an individual implementation and an issue originating from the framework, where there is no direct way to fix it ourselves. I'm honestly not sure how we should handle this right now. The error was noticed during the review process, yet the pull request was still merged. It's also easy to reproduce and will likely occur more frequently in the future. I don’t have a workaround in mind at the moment, but I haven't examined the implementation in detail yet.
Zelkreps commentedon Feb 17, 2025
itsatifsiddiqui commentedon Feb 18, 2025
@Zelkreps, I added the extra space at the bottom, if the size of the widget is larger than the available phone height, then this issue doesn't happen, it is workaround until the issue is fixed in the framework.
JosephM101 commentedon Feb 18, 2025
obenkucuk commentedon Feb 19, 2025
darshankawar commentedon Feb 19, 2025
I was able to replicate this on latest sdk versions (stable and master) which triggers the reported error log.
7 remaining items
Zelkreps commentedon Mar 4, 2025
The solution provided by @itsatifsiddiqui does not address the root cause of the problem and therefore does not work. The reason is addressed here #156381. To resolve this issue without downgrading the version, use CupertinoNavigationBar instead of CupertinoSliverNavigationBar.
itsatifsiddiqui commentedon Mar 4, 2025
Yes, the solution I provided above doesn't work effectively, but what I have noticed is if there is extra space available then, chances of happening this error is low. After adding the extra space, it was not crashing that often.
I ended up using the
ClampingScrollPhysicsOtherway around is to add the extra space at the end. Doesn't always work. But in my testing, this error was happening more if extra spacing was not added.
Fix race condition causing crash when interacting with an animating s…
Rollfreeze commentedon Mar 5, 2025
Yeah, thank you. Although CupertinoNavigationBar component has a different behavior, it's still good for iOS AppBar style
Fix race condition causing crash when interacting with an animating s…
andreykuzovlevv commentedon Mar 7, 2025
Even on Flutter 3.30.0-1.0.pre.501 • channel master •
i was still having issue with CustomScrollView and another scroll gridview widget inside it.
can't find error, already downgraded to 3.27.4, issue fixed after that
miss CupertinoNavigationBar.large btw
Fix race condition causing crash when interacting with an animating s…
[CP][Stable] Fix race condition causing crash when interacting with a…
github-actions commentedon Mar 21, 2025
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.[CP][Stable] Fix race condition causing crash when interacting with a…