flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
162.18k stars 26.64k forks source link

Failed assertion for TableExample #147411

Closed Peetee06 closed 2 weeks ago

Peetee06 commented 2 weeks ago

Steps to reproduce

  1. Create an empty flutter project
  2. Add the code from the TableExample https://pub.dev/packages/two_dimensional_scrollables/example
  3. Set diagonalDragBehavior: DiagonalDragBehavior.weightedContinuous or diagonalDragBehavior: DiagonalDragBehavior.weightedEvent in TableView.builder
  4. Run the app
  5. Scroll around

Expected results

The view scrolls without throwing an assertion.

Actual results

The view scrolls as expected but throws an assertion the moment the tap starts.

Code sample

Code sample ```dart // Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:two_dimensional_scrollables/two_dimensional_scrollables.dart'; // Print statements are only for illustrative purposes, not recommended for // production applications. // ignore_for_file: avoid_print void main() { runApp(const TableExampleApp()); } /// A sample application that utilizes the TableView API. class TableExampleApp extends StatelessWidget { /// Creates an instance of the TableView example app. const TableExampleApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Table Example', theme: ThemeData( useMaterial3: true, ), home: const TableExample(), ); } } /// The class containing the TableView for the sample application. class TableExample extends StatefulWidget { /// Creates a screen that demonstrates the TableView widget. const TableExample({super.key}); @override State createState() => _TableExampleState(); } class _TableExampleState extends State { late final ScrollController _verticalController = ScrollController(); int _rowCount = 20; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Table Example'), ), body: Padding( padding: const EdgeInsets.symmetric(horizontal: 50), child: TableView.builder( verticalDetails: ScrollableDetails.vertical(controller: _verticalController), cellBuilder: _buildCell, columnCount: 20, columnBuilder: _buildColumnSpan, rowCount: _rowCount, rowBuilder: _buildRowSpan, diagonalDragBehavior: DiagonalDragBehavior.weightedContinuous, ), ), persistentFooterButtons: [ TextButton( onPressed: () { _verticalController.jumpTo(0); }, child: const Text('Jump to Top'), ), TextButton( onPressed: () { _verticalController .jumpTo(_verticalController.position.maxScrollExtent); }, child: const Text('Jump to Bottom'), ), TextButton( onPressed: () { setState(() { _rowCount += 10; }); }, child: const Text('Add 10 Rows'), ), ], ); } TableViewCell _buildCell(BuildContext context, TableVicinity vicinity) { return TableViewCell( child: Center( child: Text('Tile c: ${vicinity.column}, r: ${vicinity.row}'), ), ); } TableSpan _buildColumnSpan(int index) { const TableSpanDecoration decoration = TableSpanDecoration( border: TableSpanBorder( trailing: BorderSide(), ), ); switch (index % 5) { case 0: return TableSpan( foregroundDecoration: decoration, extent: const FixedTableSpanExtent(100), onEnter: (_) => print('Entered column $index'), recognizerFactories: { TapGestureRecognizer: GestureRecognizerFactoryWithHandlers( () => TapGestureRecognizer(), (TapGestureRecognizer t) => t.onTap = () => print('Tap column $index'), ), }, ); case 1: return TableSpan( foregroundDecoration: decoration, extent: const FractionalTableSpanExtent(0.5), onEnter: (_) => print('Entered column $index'), cursor: SystemMouseCursors.contextMenu, ); case 2: return TableSpan( foregroundDecoration: decoration, extent: const FixedTableSpanExtent(120), onEnter: (_) => print('Entered column $index'), ); case 3: return TableSpan( foregroundDecoration: decoration, extent: const FixedTableSpanExtent(145), onEnter: (_) => print('Entered column $index'), ); case 4: return TableSpan( foregroundDecoration: decoration, extent: const FixedTableSpanExtent(200), onEnter: (_) => print('Entered column $index'), ); } throw AssertionError( 'This should be unreachable, as every index is accounted for in the switch clauses.'); } TableSpan _buildRowSpan(int index) { final TableSpanDecoration decoration = TableSpanDecoration( color: index.isEven ? Colors.purple[100] : null, border: const TableSpanBorder( trailing: BorderSide( width: 3, ), ), ); switch (index % 3) { case 0: return TableSpan( backgroundDecoration: decoration, extent: const FixedTableSpanExtent(50), recognizerFactories: { TapGestureRecognizer: GestureRecognizerFactoryWithHandlers( () => TapGestureRecognizer(), (TapGestureRecognizer t) => t.onTap = () => print('Tap row $index'), ), }, ); case 1: return TableSpan( backgroundDecoration: decoration, extent: const FixedTableSpanExtent(65), cursor: SystemMouseCursors.click, ); case 2: return TableSpan( backgroundDecoration: decoration, extent: const FractionalTableSpanExtent(0.15), ); } throw AssertionError( 'This should be unreachable, as every index is accounted for in the switch clauses.'); } } ```

Screenshots or Video

Screenshots / Video demonstration [Upload media here]

Logs

Logs ```console ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════ The following assertion was thrown while handling a gesture: 'package:flutter/src/widgets/scrollable.dart': Failed assertion: line 822 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._handleDragDown (package:flutter/src/widgets/scrollable.dart:822:12) #3 _VerticalOuterDimensionState._handleDragDown (package:flutter/src/widgets/scrollable.dart:2127:30) #4 DragGestureRecognizer._checkDown. (package:flutter/src/gestures/monodrag.dart:506:51) #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:315:24) #6 DragGestureRecognizer._checkDown (package:flutter/src/gestures/monodrag.dart:506:7) #7 DragGestureRecognizer._addPointer (package:flutter/src/gestures/monodrag.dart:358:7) #8 DragGestureRecognizer.addAllowedPointer (package:flutter/src/gestures/monodrag.dart:370:5) #9 GestureRecognizer.addPointer (package:flutter/src/gestures/recognizer.dart:217:7) #10 RawGestureDetectorState._handlePointerDown (package:flutter/src/widgets/gesture_detector.dart:1509:18) #11 RenderPointerListener.handleEvent (package:flutter/src/rendering/proxy_box.dart:3075:29) #12 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:475:22) #13 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:430:11) #14 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:420:7) #15 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:383:5) #16 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:330:7) #17 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:299:9) #18 _invoke1 (dart:ui/hooks.dart:328:13) #19 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:429:7) #20 _dispatchPointerDataPacket (dart:ui/hooks.dart:262:31) (elided 2 frames from class _AssertionError) Handler: "onDown" Recognizer: VerticalDragGestureRecognizer#65f49 ```

Flutter Doctor output

Doctor output ```console [✓] Flutter (Channel stable, 3.19.5, on macOS 14.4.1 23E224 darwin-arm64, locale en-DE) • Flutter version 3.19.5 on channel stable at /Users/petertrost/fvm/versions/3.19.5 • Upstream repository https://github.com/flutter/flutter.git • Framework revision 300451adae (4 weeks ago), 2024-03-27 21:54:07 -0500 • Engine revision e76c956498 • Dart version 3.3.3 • DevTools version 2.31.1 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/petertrost/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • ANDROID_HOME = /Users/petertrost/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15E204a • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2022.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 17.0.6+0-17.0.6b829.9-10027231) [✓] VS Code (version 1.88.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.86.0 [✓] Connected device (4 available) • iPhone 11 von Peter (mobile) • 00008030-00096D8E3EDB802E • ios • iOS 17.4.1 21E236 • iPhone 15 (mobile) • F30EE683-7178-4C38-900B-10024CE55715 • ios • com.apple.CoreSimulator.SimRuntime.iOS-17-4 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.4.1 23E224 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 124.0.6367.79 [✓] Network resources • All expected network resources are available. ```
Peetee06 commented 2 weeks ago

Update: this only occurs when hot reloading after making the change. After hot restart, everything works fine 👍

danagbemava-nc commented 2 weeks ago

Closing this as a duplicate of https://github.com/flutter/flutter/issues/14452.

github-actions[bot] commented 5 days ago

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.