Skip to content

DraggableScrollableSheet with snap: '_hold == null' assertion when a touch lifts during the snap #195744

Description

@sehangel

Steps to reproduce

  1. Open a modal bottom sheet holding a DraggableScrollableSheet with snap: true.
  2. Drag the sheet so it stops between snap sizes, and release. It starts snapping.
  3. While it snaps, touch the sheet and lift the finger without dragging.

Expected results

No assertion. The touch's hold on the scroll position ends when the finger lifts.

Actual results

'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 907 pos 12: '_hold == null': is not true.

The assertion is in ScrollableState._handleDragCancel. A second touch before the snap ends fails the matching assertion in _handleDragDown (line 865). Only debug builds show it, because it is an assert.

From reading the source, the cause looks like this:

  1. The touch calls position.hold(), which starts a HoldScrollActivity. _DraggableScrollableSheetPosition.beginActivity stops the running snap, so the sheet rests between sizes.
  2. Lifting the finger calls _handleDragCancel and then _hold.cancel(), which calls goBallistic(0).
  3. _shouldSnap() is true, so goBallistic skips super.goBallistic. It calls _dragCancelCallback, which is null for a hold, and starts its own AnimationController without calling beginActivity.
  4. The hold activity is not disposed, so _disposeHold does not run before the assert.

_DraggableScrollableSheetPosition overrides drag to save the cancel callback, but it has no equivalent for hold. The same goBallistic code is on master.

Code sample

This is a test that fails on the expect:

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('a touch lifted while the sheet snaps', (tester) async {
    tester.view
      ..devicePixelRatio = 1
      ..physicalSize = const Size(400, 800);
    addTearDown(tester.view.reset);
    await tester.pumpWidget(
      const MaterialApp(home: Scaffold(body: SizedBox.expand())),
    );
    showModalBottomSheet<void>(
      context: tester.element(find.byType(Scaffold)),
      isScrollControlled: true,
      builder: (_) => DraggableScrollableSheet(
        expand: false,
        initialChildSize: 2 / 3,
        minChildSize: 1 / 3,
        snap: true,
        snapSizes: const [2 / 3],
        builder: (_, controller) => SingleChildScrollView(
          controller: controller,
          child: Column(
            children: [for (var i = 0; i < 40; i++) Text('Line $i')],
          ),
        ),
      ),
    );
    await tester.pumpAndSettle();

    final line = find.text('Line 3');
    final drag = await tester.startGesture(tester.getCenter(line));
    await drag.moveBy(const Offset(0, -60));
    await tester.pump();
    await drag.moveBy(const Offset(0, -60));
    await tester.pump();
    await drag.up();
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 16));

    final touch = await tester.startGesture(tester.getCenter(line));
    await tester.pump();
    await touch.up();
    await tester.pump();
    expect(tester.takeException(), isNull);

    await tester.pumpAndSettle();
  });
}

The same sheet placed directly in a Scaffold body did not fail in my test. I did not look into why.

Screenshots or Video

Not applicable. There is no visible symptom beyond the assertion.

Logs

Top of the stack, from a debug build on a physical Android 13 device:

#0 ScrollableState._handleDragCancel (package:flutter/src/widgets/scrollable.dart:907)
#1 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:362)
#2 DragGestureRecognizer._checkCancel (package:flutter/src/gestures/monodrag.dart:904)
#3 DragGestureRecognizer.didStopTrackingLastPointer (package:flutter/src/gestures/monodrag.dart:761)
#4 OneSequenceGestureRecognizer.stopTrackingPointer (package:flutter/src/gestures/recognizer.dart:556)
#5 DragGestureRecognizer._giveUpPointer (package:flutter/src/gestures/monodrag.dart:773)
#6 DragGestureRecognizer.handleEvent (package:flutter/src/gestures/monodrag.dart:725)

Flutter Doctor output

flutter --version:

Flutter 3.47.7 • channel stable • 
Framework • revision abaf9c5237 (3 weeks ago) • 2026-10-08 09:51:21 -0700
Engine • hash d8a2d6c768c334d53e16277f837970ffa1e2de81 (revision deb287481e) (24 days ago) • 2026-10-07 17:09:12.000Z
Tools • Dart 3.13.5 • DevTools 2.60.0

Activity

  1. added
    in triage
    on Nov 2, 2026
  2. suryaKommana2662 commented on Nov 2, 2026

    @suryaKommana2662
    Contributor

    @sehangel Thanks for the report. I was able to reproduce this issue locally using the provided test case. Routing to team-framework for further investigation.

    Result: The test fails with the following assertion:

    ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
    The following TestFailure was thrown running a test:
    Expected: null
      Actual: _AssertionError:<'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 908
    pos 12: '_hold == null': is not true.>
    
    When the exception was thrown, this was the stack:
    #4      main.<anonymous closure> (file:///Users/suryakommana/StudioProjects/default_app/test/widget_test.dart:46:5)
    <asynchronous suspension>
    #5      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:192:15)
    <asynchronous suspension>
    #6      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:2068:5)
    <asynchronous suspension>
    <asynchronous suspension>
    (elided one frame from package:stack_trace)
    
    This was caught by the test expectation on the following line:
      file:///Users/suryakommana/StudioProjects/default_app/test/widget_test.dart line 46
    The test description was:
      a touch lifted while the sheet snaps
    ════════════════════════════════════════════════════════════════════════════════════════════════════
    00:01 +0 -1: a touch lifted while the sheet snaps [E]                                                                                                                 
      Test failed. See exception logs above.
      The test description was: a touch lifted while the sheet snaps
      
    
    To run this test again: /Users/suryakommana/develop/flutter/bin/cache/dart-sdk/bin/dart test /Users/suryakommana/StudioProjects/default_app/test/widget_test.dart -p vm --plain-name 'a touch lifted while the sheet snaps'
    00:01 +0 -1: Some tests failed.  
    

    This appears related to #172174, as both involve the _hold == null assertion. However, #172174 involves interrupting a scroll in a PageView and SingleChildScrollView, whereas this issue occurs when a touch is lifted during a DraggableScrollableSheet snap animation. Therefore, I'm keeping this as a separate issue rather than marking it as a duplicate.

    Flutter Doctor Output

    [✓] Flutter (Channel master, 3.50.0-1.0.pre-340, on macOS 27.0 26A428 darwin-arm64, locale en-IN) [2.6s]
        • Flutter version 3.50.0-1.0.pre-340 on channel master at /Users/suryakommana/develop/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision ef74a07661 (3 hours ago), 2026-11-02 03:14:25 +0000
        • Engine revision ef74a07661
        • Dart version 3.15.0 (build 3.15.0-101.0.dev)
        • DevTools version 2.62.0-dev.0
        • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets,
          enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration, enable-riscv64, enable-hcpp
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [2.4s]
        • Android SDK at /Users/suryakommana/Library/Android/sdk
        • Emulator version 37.1.11.0 (build_id 15917651) (CL:N/A)
        • Platform android-37.0, build-tools 36.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
          This is the JDK bundled with the latest Android Studio installation on this machine.
          To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 25.0.2+-15348964-b329.117)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 27.2) [2.4s]
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 27B52
        • CocoaPods version 1.17.0
    
    [✓] Chrome - develop for the web [4ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Connected device (2 available) [5.9s]
        • macOS (desktop) • macos  • darwin-arm64   • macOS 27.0 26A428 darwin-arm64
        • Chrome (web)    • chrome • web-javascript • Google Chrome 156.0.8078.76
    
    [✓] Network resources [715ms]
        • All expected network resources are available.
    
    • No issues found!
  3. added
    a: tests
    framework
    f: scrolling
    has reproducible steps
    team-framework
    and removed
    in triage
    on Nov 2, 2026
  4. added
    P2
    triaged-framework
    on Nov 3, 2026
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

    P2a: testsf: scrollingframeworkhas reproducible stepsteam-frameworktriaged-framework

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions