Repository: flutter
Issue: 'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 842 pos 12: '_hold == null': is not true.
Labels: waiting for customer response,in triage

### Steps to reproduce

I wanted to create an instant return effect so that the header would always be open or closed.


Essentially this code works, but at some point it produces a critical error and scrolling stops working.



### Expected results

.

### Actual results

/

### Code sample

<details open><summary>Code sample</summary>

```dart

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(
      darkTheme: ThemeData.dark(),
      themeMode: ThemeMode.dark,
    );
  }
}

class TelegramStyleAppBar extends StatefulWidget {
  const TelegramStyleAppBar({super.key});

  @override
  _TelegramStyleAppBarState createState() => _TelegramStyleAppBarState();
}

class _TelegramStyleAppBarState extends State<TelegramStyleAppBar> {
  late ScrollController _scrollController;

  double expandedHeight = 300.0;
  double collapsedHeight = 100.0;

  @override
  void initState() {
    super.initState();

    _scrollController = ScrollController();

    // Инициализация слушателей

    WidgetsBinding.instance.addPostFrameCallback(
      (timeStamp) {
        print(_scrollController.position);
        _scrollController.position.isScrollingNotifier.addListener(
          () {
            if (!_scrollController.position.isScrollingNotifier.value) {
              _handleSnapScroll();
            }
          },
        );
      },
    );
  }

  @override
  void dispose() {
    _scrollController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body: CustomScrollView(
        controller: _scrollController,
        physics: const BouncingScrollPhysics(),
        slivers: [
          SliverAppBar(
            pinned: true,
            stretch: true,
            surfaceTintColor: Colors.transparent,
            expandedHeight: expandedHeight,
            collapsedHeight: collapsedHeight,
            backgroundColor: Colors.black,
            flexibleSpace: LayoutBuilder(
              builder: (BuildContext context, BoxConstraints constraints) {
                final appBarHeight = constraints.biggest.height;
                final normalizedHeight = (appBarHeight - collapsedHeight) /
                    (expandedHeight - collapsedHeight);
                final clampedHeight = normalizedHeight.clamp(0.0, 1.0);

                return FlexibleSpaceBar(
                  centerTitle: true,
                  title: Opacity(
                    opacity: 1,
                    child: Text(
                      'Telegram Header',
                      style: TextStyle(
                        fontSize: 20 + clampedHeight * 10,
                        color: Colors.white,
                      ),
                    ),
                  ),
                  background: Container(
                    color: Colors.blue,
                    child: Center(
                      child: Text(
                        'Pull to Stretch',
                        style: TextStyle(
                          fontSize: 16 + clampedHeight * 24,
                          color: Colors.white,
                        ),
                      ),
                    ),
                  ),
                );
              },
            ),
          ),
          SliverList(
            delegate: SliverChildBuilderDelegate(
              (context, index) => ListTile(
                title: Text('Item $index'),
              ),
              childCount: 50,
            ),
          ),
        ],
      ),
    );
  }

  void _handleSnapScroll() async {
    double offset = _scrollController.offset;
    double snapThreshold = (expandedHeight - collapsedHeight) / 2;

    // Проверка, на какой позиции находится скролл
    if (offset < snapThreshold) {
      // Скролл до раскрытой шапки
      await _scrollController.animateTo(
        0.0,
        duration: const Duration(milliseconds: 300),
        curve: Curves.easeInOut,
      );
    } else if (offset < expandedHeight - collapsedHeight) {
      // Скролл до свернутой шапки
      await _scrollController.animateTo(
        expandedHeight - collapsedHeight,
        duration: const Duration(milliseconds: 300),
        curve: Curves.easeInOut,
      );
    }
  }
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
Restarted application in 432ms.
flutter: ScrollPositionWithSingleContext#5d946(offset: 0.0, range: 0.0..2288.0, viewport: 874.0, ScrollableState, BouncingScrollPhysics -> BouncingScrollPhysics -> RangeMaintainingScrollPhysics, IdleScrollActivity#a82a1, ScrollDirection.idle)
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not find font in the atlas.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not find font in the atlas.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not find font in the atlas.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not find font in the atlas.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not find font in the atlas.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not find font in the atlas.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not find font in the atlas.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not find font in the atlas.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not find font in the atlas.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not find font in the atlas.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not find font in the atlas.
[ERROR:flutter/impeller/base/validation.cc(59)] Break on 'ImpellerValidationBreak' to inspect point of failure: Could not find font in the atlas.

════════ Exception caught by gesture ═══════════════════════════════════════════
The following assertion was thrown while handling a gesture:
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 842 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:842:12)
#3      DragGestureRecognizer._checkStart.<anonymous closure> (package:flutter/src/gestures/monodrag.dart:790:53)
#4      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:351:24)
#5      DragGestureRecognizer._checkStart (package:flutter/src/gestures/monodrag.dart:790:7)
#6      DragGestureRecognizer._checkDrag (package:flutter/src/gestures/monodrag.dart:757:5)
#7      DragGestureRecognizer.acceptGesture (package:flutter/src/gestures/monodrag.dart:684:7)
#8      GestureArenaManager._resolveByDefault (package:flutter/src/gestures/arena.dart:271:25)
#9      GestureArenaManager._tryToResolveArena.<anonymous closure> (package:flutter/src/gestures/arena.dart:251:31)
(elided 4 frames from class _AssertionError and dart:async)

Handler: "onStart"
Recognizer: VerticalDragGestureRecognizer#9732c
    start behavior: start
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 847 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 847 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 847 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 847 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 847 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 847 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 847 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 847 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 847 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 847 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 847 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 847 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 847 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 847 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 847 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════
'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 853 pos 12: '_hold == null || _drag == null': is not true.
════════════════════════════════════════════════════════════════════════════════
Reloaded 1 of 709 libraries in 394ms (compile: 38 ms, reload: 161 ms, reassemble: 135 ms).
Reloaded 1 of 709 libraries in 328ms (compile: 43 ms, reload: 103 ms, reassemble: 91 ms).

```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
f%                                                                                                                                                        
a001@MacBook-exeshka telegram_ui % flutter doctor -v 
[✓] Flutter (Channel stable, 3.24.5, on macOS 15.2 24C101 darwin-arm64, locale ru-KZ)
    • Flutter version 3.24.5 on channel stable at /Users/a001/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision dec2ee5c1f (9 weeks ago), 2024-11-13 11:13:06 -0800
    • Engine revision a18df97ca5
    • Dart version 3.5.4
    • DevTools version 2.37.3

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /Users/a001/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: /opt/homebrew/Cellar/openjdk@17/17.0.13/libexec/openjdk.jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment Homebrew (build 17.0.13+0)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.2)
    • 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
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)

[✓] VS Code (version 1.95.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (5 available)
    • iPhone exeshka (mobile)         • 00008101-0015148A0C40001E            • ios            • iOS 18.2 22C150
    • iPhone 16 Pro (mobile)          • 54FA6352-39FF-44D9-8BB9-ADF8BCF9E69E • ios            • com.apple.CoreSimulator.SimRuntime.iOS-18-2 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 15.2 24C101 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 15.2 24C101 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 131.0.6778.266

[✓] Network resources
    • All expected network resources are available.

• No issues found!
a001@MacBook-exeshka telegram_ui % 
```

</details>