Skip to content

Assertion Error using CustomScrollView with CupertinoSliverNavigationBar (Flutter 3.29) #163297

Closed

Description

@bobekos

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:

  1. Run the provided code.
  2. Scroll up or down on the navigation bar multiple times.
  3. Observe the assertion errors in the debug console.
  4. 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.2

Activity

  1. self-assigned this
    on Feb 14, 2025
  2. victorsanni commented on Feb 14, 2025

    @victorsanni
    Contributor
  3. victorsanni commented on Feb 14, 2025

    @victorsanni
    Contributor

    The underlying issue is that under the hood we use ScrollPosition.animateTo to 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.

  4. bobekos commented on Feb 15, 2025

    @bobekos
    Author

    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.

  5. Zelkreps commented on Feb 17, 2025

    @Zelkreps
  6. itsatifsiddiqui commented on Feb 18, 2025

    @itsatifsiddiqui

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

  7. JosephM101 commented on Feb 18, 2025

    @JosephM101
  8. obenkucuk commented on Feb 19, 2025

    @obenkucuk
  9. darshankawar commented on Feb 19, 2025

    @darshankawar
    Member

    I was able to replicate this on latest sdk versions (stable and master) which triggers the reported error log.

    stable : 3.29.0
    master : 3.30.0-1.0.pre.191
    
  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
    on Feb 19, 2025
  11. 7 remaining items

  12. Zelkreps commented on Mar 4, 2025

    @Zelkreps

    Hello. I also encountered this problem at Flutter 3.29.0 version.

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

    Tried this way but it didn't work for me. Can you please provide full code to show your solution?

    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.

  13. itsatifsiddiqui commented on Mar 4, 2025

    @itsatifsiddiqui

    Hello. I also encountered this problem at Flutter 3.29.0 version.

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

    Tried this way but it didn't work for me. Can you please provide full code to show your solution?

    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.

    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 ClampingScrollPhysics

    CustomScrollView(
          physics: ClampingScrollPhysics(),
          slivers: [
                .
                .
                .
                
                //Other widgets here.
                .
                .
                .
          ],
        );
    

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

    CustomScrollView(
          slivers: [
            SliverList.list(children: [
    
                .
                .
                .
                
                //Other widgets here.
                .
                .
                .
                SizedBox(height: 500) , /// Adding this extra space reduces the chances of this exception.
              ],
            )
          ],
        );
  14. Rollfreeze commented on Mar 5, 2025

    @Rollfreeze

    Hello. I also encountered this problem at Flutter 3.29.0 version.

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

    Tried this way but it didn't work for me. Can you please provide full code to show your solution?

    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.

    Yeah, thank you. Although CupertinoNavigationBar component has a different behavior, it's still good for iOS AppBar style

  15. added
    r: fixedIssue is closed as already fixed in a newer version
    on Mar 5, 2025
  16. andreykuzovlevv commented on Mar 7, 2025

    @andreykuzovlevv

    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

  17. github-actions commented on Mar 21, 2025

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

  18. locked as resolved and limited conversation to collaborators on Mar 21, 2025
  19. removed their assignment
    on May 15, 2025
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

    c: crashStack traces logged to the consolef: scrollingViewports, list views, slivers, etc.found in release: 3.29Found to occur in 3.29found in release: 3.30Found to occur in 3.30frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: cupertino_uicupertino_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions