Repository: flutter
Issue: ListView with addRepaintBoundaries and addSemanticIndexes both set to false crashes
Labels: framework,f: scrolling,a: error message,has reproducible steps,P2,team-framework,triaged-framework,found in release: 3.22,found in release: 3.23

### Steps to reproduce

When you create a ListView with addRepaintBoundaries and addSemanticIndexes both set to false and you have a StatefulWidget in it that rebuilds into a different widget it will trigger an exception.

### Expected results

On rebuild the StatefulWidget contained in the list should simply change to its newly built widget.

### Actual results

The application crashes.

### Code sample

Dartpad: <a href="https://dartpad.dev/?id=b176ac19eb996a2b22fedba7fd52b937" target="_blank">Example</a>
<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(
    Directionality(
      textDirection: TextDirection.ltr,
      child: ListView(
        addRepaintBoundaries: false,
        addSemanticIndexes: false,
        children: [
          TapToToggle(),
        ],
      ),
    ),
  );
}

class TapToToggle extends StatefulWidget {
  @override
  _TapToToggleState createState() => _TapToToggleState();
}

class _TapToToggleState extends State<TapToToggle> {
  bool showText = false;

  void toggleDisplay() {
    setState(() {
      showText = !showText;
    });
  }

  @override
  Widget build(BuildContext context) {
    if (showText) {
      return Text('Crashed', style: TextStyle(fontSize: 24));
    }
    return GestureDetector(
      onTap: toggleDisplay,
      child: Container(
        height: 100.0,
        color: Colors.white,
        child: Center(child: Text('Click me to Crash!', style: TextStyle(fontSize: 24)))
      ),
    );
  }
}
```

</details>


### Screenshots or Video

_No response_

### Logs

<details open><summary>Logs</summary>

```console
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown building TapToToggle(state: _TapToToggleState#87ac2):
'package:flutter/src/widgets/sliver.dart': Failed assertion: line 1149 pos 12:
'_currentlyUpdatingChildIndex != 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:
  TapToToggle TapToToggle:file:///home/user/flutter/examples/testing/lib/main.dart:11:11

When the exception was thrown, this was the stack:
#2      SliverMultiBoxAdaptorElement.removeRenderObjectChild (package:flutter/src/widgets/sliver.dart:1149:12)
#3      RenderObjectElement.detachRenderObject (package:flutter/src/widgets/framework.dart:6611:37)
#4      Element.detachRenderObject.<anonymous closure> (package:flutter/src/widgets/framework.dart:4199:13)
#5      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5533:14)
#6      Element.detachRenderObject (package:flutter/src/widgets/framework.dart:4198:5)
#7      Element.detachRenderObject.<anonymous closure> (package:flutter/src/widgets/framework.dart:4199:13)
#8      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5533:14)
#9      Element.detachRenderObject (package:flutter/src/widgets/framework.dart:4198:5)
#10     Element.deactivateChild (package:flutter/src/widgets/framework.dart:4375:11)
#11     Element.updateChild (package:flutter/src/widgets/framework.dart:3832:9)
#12     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5506:16)
#13     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5644:11)
#14     Element.rebuild (package:flutter/src/widgets/framework.dart:5197:7)
#15     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2905:19)
#16     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:1136:21)
#17     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:468:5)
#18     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1392:15)
#19     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1313:9)
#20     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1171:5)
#21     _invoke (dart:ui/hooks.dart:312:13)
#22     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)
#23     _drawFrame (dart:ui/hooks.dart:283:31)
(elided 2 frames from class _AssertionError)

════════════════════════════════════════════════════════════════════════════════════════════════════
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel master, 3.22.0-18.0.pre.48, on Ubuntu 20.04.6 LTS 5.4.0-182-generic, locale en_US.UTF-8)
    • Flutter version 3.22.0-18.0.pre.48 on channel master at /home/user/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f9933b6994 (5 weeks ago), 2024-04-27 01:41:24 -0400
    • Engine revision 20fb62ba14
    • Dart version 3.5.0 (build 3.5.0-105.0.dev)
    • DevTools version 2.35.0-dev.8

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /home/user/Android/Sdk
    • Platform android-33, build-tools 34.0.0
    • Java binary at: /opt/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.6
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 2022.3)
    • Android Studio at /opt/android-studio
    • 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)

[✓] IntelliJ IDEA Ultimate Edition (version 2024.1)
    • IntelliJ at /snap/intellij-idea-ultimate/497
    • 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

[✓] VS Code (version 1.89.1)
    • VS Code at /snap/code/current/usr/share/code
    • Flutter extension version 3.88.0

[✓] Connected device (2 available)
    • Linux (desktop) • linux  • linux-x64      • Ubuntu 20.04.6 LTS 5.4.0-182-generic
    • Chrome (web)    • chrome • web-javascript • Google Chrome 123.0.6312.105

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>