Repository: flutter
Issue: [two_dimensional_scrollables] Quickly resizing a TableView throws an assertion error
Labels: package,a: error message,has reproducible steps,P2,team-framework,triaged-framework,p: two_dimensional_scrollables,found in release: 3.16,found in release: 3.18

### Steps to reproduce

1. flutter create tableview_sample
2. flutter pub add two_dimensional_scrollables (I managed to reproduce with version 0.0.5)
3. Paste the code sample into main.dart
4. Run the app
5. Drag both sliders to their maximum
6. Scroll both axes to their end, so that the tile in the bottom corner of the table view is visible on the bottom right (tile "x:63, y:63")
7. Drag the "Row" slider back to its minimum, as fast as possible. I ran the app on Windows since using a mouse makes it easy to reproduce.
8. An assert is logged, even though the table view looks fine

### Expected results

No assertions and a properly rendered table view

### Actual results

An assertion is logged when shrinking the table view

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';
import 'package:two_dimensional_scrollables/two_dimensional_scrollables.dart';

void main() {
  runApp(const MaterialApp(home: TableViewTest()));
}

class TableViewTest extends StatefulWidget {
  const TableViewTest({super.key});

  @override
  State<TableViewTest> createState() => _TableViewTestState();
}

class _TableViewTestState extends State<TableViewTest> {
  int rows = 1;
  int columns = 1;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('TableView example'),
      ),
      body: Row(
        children: [
          Expanded(
            child: TableView.builder(
              columnCount: columns,
              rowCount: rows,
              columnBuilder: (int index) => const TableSpan(
                extent: FixedTableSpanExtent(64),
              ),
              rowBuilder: (int index) => const TableSpan(
                extent: FixedTableSpanExtent(64),
              ),
              cellBuilder: (context, vicinity) => Container(
                decoration: BoxDecoration(
                  border: Border.all(color: Colors.red),
                ),
                width: 64,
                height: 64,
                child: Center(
                  child: Text('x: ${vicinity.xIndex} y: ${vicinity.yIndex}'),
                ),
              ),
            ),
          ),
          SizedBox(
            width: 200,
            child: Column(
              children: [
                const Text('Rows'),
                Slider(
                  min: 1,
                  max: 64,
                  value: rows.toDouble(),
                  onChanged: (value) {
                    if (mounted) {
                      setState(() {
                        rows = value.floor();
                      });
                    }
                  },
                ),
                const Text('Columns'),
                Slider(
                  min: 1,
                  max: 64,
                  value: columns.toDouble(),
                  onChanged: (value) {
                    if (mounted) {
                      setState(() {
                        columns = value.floor();
                      });
                    }
                  },
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
PS C:\Users\Navaron\Desktop\tableview_sample> flutter run
Launching lib\main.dart on Windows in debug mode...
Building Windows application...                                    11,1s
√  Built build\windows\x64\runner\Debug\tableview_sample.exe.
Syncing files to device Windows...                                  98ms

Flutter run key commands.
r Hot reload.
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

A Dart VM Service on Windows is available at: http://127.0.0.1:51886/KWVYjXmcjOE=/
The Flutter DevTools debugger and profiler on Windows is available at: http://127.0.0.1:9101?uri=http://127.0.0.1:51886/KWVYjXmcjOE=/

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during performLayout():
'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12:
'_leadingXIndex != 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

The relevant error-causing widget was:
  TableViewport
  TableViewport:file:///C:/Users/Navaron/AppData/Local/Pub/Cache/hosted/pub.dev/two_dimensional_scrollables-0.0.5/lib/src/table_view/table.dart:191:12

When the exception was thrown, this was the stack:
#2      RenderTwoDimensionalViewport._reifyChildren (package:flutter/src/widgets/two_dimensional_viewport.dart:1289:12)
#3      RenderTwoDimensionalViewport.performLayout.<anonymous closure> (package:flutter/src/widgets/two_dimensional_viewport.dart:1268:7)
#4      RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:2657:59)
#5      PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:1071:15)
#6      RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:2657:14)
#7      RenderTwoDimensionalViewport.performLayout (package:flutter/src/widgets/two_dimensional_viewport.dart:1258:5)
#8      RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:2385:7)
#9      PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1025:18)
#10     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1038:15)
#11     RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:591:23)
#12     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:986:13)
#13     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:457:5)
#14     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1325:15)
#15     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1255:9)
#16     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1113:5)
#17     _invoke (dart:ui/hooks.dart:312:13)
#18     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:383:5)
#19     _drawFrame (dart:ui/hooks.dart:283:31)
(elided 2 frames from class _AssertionError)

The following RenderObject was being processed when the exception was fired: RenderTableViewport#7cad0 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE:
  needs compositing
  creator: TableViewport ← IgnorePointer-[GlobalKey#ebb8b] ← Semantics ← Listener ← _GestureSemantics
    ← RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#eaa89] ← Listener ←
    _ScrollableScope ← _ScrollSemantics-[GlobalKey#07bcc] ←
    NotificationListener<ScrollMetricsNotification> ←
    _HorizontalInnerDimension-[LabeledGlobalKey<ScrollableState>#28b0c] ←
    IgnorePointer-[GlobalKey#1889c] ← ⋯
  parentData: <none> (can use size)
  constraints: BoxConstraints(w=1064.0, 0.0<=h<=625.0)
  layer: OffsetLayer#142e1
  size: Size(1064.0, 625.0)
This RenderObject has no descendants.
════════════════════════════════════════════════════════════════════════════════════════════════════

Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.
Another exception was thrown: 'package:flutter/src/widgets/two_dimensional_viewport.dart': Failed assertion: line 1289 pos 12: '_leadingXIndex != null': is not true.

Application finished.
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[√] Flutter (Channel stable, 3.16.5, on Microsoft Windows [Version 10.0.19045.3803], locale nl-BE)
    • Flutter version 3.16.5 on channel stable at E:\Documenten\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 78666c8dc5 (5 days ago), 2023-12-19 16:14:14 -0800        
    • Engine revision 3f3e560236
    • Dart version 3.2.3
    • DevTools version 2.28.4

[√] Windows Version (Installed version of Windows is version 10 or higher)

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)   
    • Android SDK at E:\Android\Sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = E:\Android\Sdk
    • Java binary at: E:\Android\AndroidStudio\jre\bin\java
    X Cannot execute E:\Android\AndroidStudio\jre\bin\java to determine the version

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe        

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.6)
    • Visual Studio at E:\Program Files\VisualStudio
    • Visual Studio Community 2022 version 17.7.34221.43
    • Windows 10 SDK version 10.0.22621.0

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19045.3803]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 103.0.5060.134
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 120.0.2210.91

[√] Network resources
    • All expected network resources are available.

! Doctor found issues in 2 categories.
```

</details>