Skip to content

DraggableScrollableSheet with BouncingScrollPhysics throw exception when closed too fast with scroll #101061

@SuperPenguin

Description

@SuperPenguin

Steps to Reproduce

  1. Run code below
  2. Press open
  3. Drag the list up then drag it down really fast

Expected results: No exception

Actual results: Get exception when closed with scrolled down too fast, when scrolled slowly, it doesn't throw exception

Code sample
import 'package:flutter/material.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  runApp(const App());
}

class App extends StatelessWidget {
  const App({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Home(),
    );
  }
}

class Home extends StatelessWidget {
  const Home({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Demo'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            showModalBottomSheet(
              context: context,
              isScrollControlled: true,
              builder: (context) => const _DemoSheet(),
            );
          },
          child: const Text('Open'),
        ),
      ),
    );
  }
}

class _DemoSheet extends StatefulWidget {
  const _DemoSheet({Key? key}) : super(key: key);

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

class _DemoSheetState extends State<_DemoSheet> {
  final _data = List.generate(
    100,
    (index) => Colors.primaries[index % Colors.primaries.length],
  );

  @override
  Widget build(BuildContext context) {
    return DraggableScrollableSheet(
      initialChildSize: 0.5,
      minChildSize: 0.2,
      maxChildSize: 0.9,
      expand: false,
      builder: (context, scrollController) => ListView.separated(
        physics: const BouncingScrollPhysics(),
        controller: scrollController,
        separatorBuilder: (context, index) => const Divider(),
        itemCount: _data.length,
        itemBuilder: (context, index) => SizedBox(
          height: 100,
          child: ColoredBox(
            color: _data[index],
          ),
        ),
      ),
    );
  }
}
Logs
FlutterError (ScrollableState#436e8(tickers: tracking 2 tickers, position: _DraggableScrollableSheetScrollPosition#462ec(offset: -119.2, range: -1.0..13063.7, viewport: 150.9, ScrollableState, BouncingScrollPhysics -> BouncingScrollPhysics -> RangeMaintainingScrollPhysics, null, ScrollDirection.idle), effective physics: BouncingScrollPhysics -> BouncingScrollPhysics -> RangeMaintainingScrollPhysics) was disposed with an active Ticker.
ScrollableState created a Ticker via its TickerProviderStateMixin, but at the time dispose() was called on the mixin, that Ticker was still active. All Tickers must be disposed before calling super.dispose().
Tickers used by AnimationControllers should be disposed by calling dispose() on the AnimationController itself. Otherwise, the ticker will leak.
The offending ticker was:
  _WidgetTicker(created by ScrollableState#436e8)
  The stack trace when the _WidgetTicker was actually created was:
  #0      new Ticker.<anonymous closure> (package:flutter/src/scheduler/ticker.dart:67:40)
  #1      new Ticker (package:flutter/src/scheduler/ticker.dart:69:6)
  #2      new _WidgetTicker (package:flutter/src/widgets/ticker_provider.dart:385:81)
  #3      TickerProviderStateMixin.createTicker (package:flutter/src/widgets/ticker_provider.dart:295:34)
  #4      new AnimationController.unbounded (package:flutter/src/animation/animation_controller.dart:279:21)
  #5      _DraggableScrollableSheetScrollPosition.goBallistic (package:flutter/src/widgets/draggable_scrollable_sheet.dart:859:73)
  #6      BallisticScrollActivity.applyNewDimensions (package:flutter/src/widgets/scroll_activity.dart:549:14)
  #7      ScrollPosition.applyNewDimensions (package:flutter/src/widgets/scroll_position.dart:623:15)
  #8      ScrollPositionWithSingleContext.applyNewDimensions (package:flutter/src/widgets/scroll_position_with_single_context.dart:104:11)
  #9      ScrollPosition.applyContentDimensions (package:flutter/src/widgets/scroll_position.dart:553:7)
  #10     _DraggableScrollableSheetScrollPosition.applyContentDimensions (package:flutter/src/widgets/draggable_scrollable_sheet.dart:794:18)
  #11     RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1493:20)
  #12     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1731:7)
  #13     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:887:18)
  #14     RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:497:19)
  #15     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:883:13)
  #16     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:363:5)
  #17     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144:15)
  #18     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1081:9)
  #19     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:995:5)
  #23     _invoke (dart:ui/hooks.dart:151:10)
  #24     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308:5)
  #25     _drawFrame (dart:ui/hooks.dart:115:31)
  (elided 3 frames from dart:async))
[✓] Flutter (Channel unknown, 2.10.4, on macOS 12.1 21C52 darwin-arm, locale en-ID)
    • Flutter version 2.10.4 at /Users/s21/Documents/GitHub/flutter/flutter
    • Upstream repository unknown
    • Framework revision c860cba910 (5 days ago), 2022-03-25 00:23:12 -0500
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/s21/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

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

[✓] Android Studio (version 2020.3)
    • 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 11.0.10+0-b96-7249189)

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

[✓] Connected device (3 available)
    • iPhone SE (3rd generation) (mobile) • E31DBB95-A1F1-4893-AF0C-48C839A6A434 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-4 (simulator)
    • macOS (desktop)                     • macos                                • darwin-arm64   • macOS 12.1 21C52 darwin-arm
    • Chrome (web)                        • chrome                               • web-javascript • Google Chrome 99.0.4844.84

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
Screen.Recording.2022-03-30.at.22.59.27.mov

Metadata

Metadata

Assignees

Labels

a: error messageError messages from the Flutter frameworkc: crashStack traces logged to the consolef: material designflutter/packages/flutter/material repository.f: scrollingViewports, list views, slivers, etc.found in release: 2.10Found to occur in 2.10found in release: 2.13Found to occur in 2.13frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions