Repository: flutter
Issue: NavigatorState._flushHistoryUpdates RangeError (length): Invalid value: Valid value range is empty: -1
Labels: c: crash,framework,f: routes,a: production,P2,needs repro info,team-framework,triaged-framework

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

Just don't know how it occurs and crash happened not in 100% so it's hard to reproduce. Most users crash in initial steps, and I have implemented restore mechanism in some pages, some are not. Also it seems only occur in Android phone. Any idea?

### Expected results

Should work fine and not crash

### Actual results

Crash sometimes and don't know why

### Code sample

<details><summary>Code sample</summary>

```dart
Just don't know how it occurs, so having no sample here
```

</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>



</details>


### Logs

<details><summary>Logs</summary>

```console
Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: RangeError (length): Invalid value: Valid value range is empty: -1. Error thrown Instance of 'qH'.
#00 pc 0x33a993 com.gogolook.rooney (NavigatorState._flushHistoryUpdates [navigator.dart:3885])
#01 pc 0x53110b com.gogolook.rooney (NavigatorState.restoreState [navigator.dart:3387])
#02 pc 0x530ed3 com.gogolook.rooney (RestorationMixin._doRestore [restoration.dart:917])
#03 pc 0x530e6b com.gogolook.rooney (RestorationMixin.didChangeDependencies [restoration.dart:903])
#04 pc 0x530bb7 com.gogolook.rooney (NavigatorState.didChangeDependencies [navigator.dart:3405])
#05 pc 0x6a687f com.gogolook.rooney (StatefulElement._firstBuild [framework.dart:5119])
#06 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#07 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#08 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#09 pc 0x6a67e3 com.gogolook.rooney (ComponentElement._firstBuild [framework.dart:4690])
#10 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#11 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#12 pc 0x47bbbb com.gogolook.rooney (SingleChildRenderObjectElement.mount [framework.dart:3682])
#13 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#14 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#15 pc 0x3c5537 com.gogolook.rooney (StatefulElement.performRebuild [framework.dart:5133])
#16 pc 0x6a68af com.gogolook.rooney (StatefulElement._firstBuild [framework.dart:4690])
#17 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#18 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#19 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#20 pc 0x6a67e3 com.gogolook.rooney (ComponentElement._firstBuild [framework.dart:4690])
#21 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#22 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#23 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#24 pc 0x3c5537 com.gogolook.rooney (StatefulElement.performRebuild [framework.dart:5133])
#25 pc 0x6a68af com.gogolook.rooney (StatefulElement._firstBuild [framework.dart:4690])
#26 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#27 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#28 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#29 pc 0x3c5537 com.gogolook.rooney (StatefulElement.performRebuild [framework.dart:5133])
#30 pc 0x6a68af com.gogolook.rooney (StatefulElement._firstBuild [framework.dart:4690])
#31 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#32 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#33 pc 0x47b907 com.gogolook.rooney (MultiChildRenderObjectElement.mount [framework.dart:6512])
#34 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#35 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#36 pc 0x3c5537 com.gogolook.rooney (StatefulElement.performRebuild [framework.dart:5133])
#37 pc 0x6a68af com.gogolook.rooney (StatefulElement._firstBuild [framework.dart:4690])
#38 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#39 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#40 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#41 pc 0x6a67e3 com.gogolook.rooney (ComponentElement._firstBuild [framework.dart:4690])
#42 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#43 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#44 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#45 pc 0x3c5537 com.gogolook.rooney (StatefulElement.performRebuild [framework.dart:5133])
#46 pc 0x6a68af com.gogolook.rooney (StatefulElement._firstBuild [framework.dart:4690])
#47 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#48 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#49 pc 0x47bbbb com.gogolook.rooney (SingleChildRenderObjectElement.mount [framework.dart:3682])
#50 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#51 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#52 pc 0x6a67e3 com.gogolook.rooney (ComponentElement._firstBuild [framework.dart:4690])
#53 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#54 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#55 pc 0x47bbbb com.gogolook.rooney (SingleChildRenderObjectElement.mount [framework.dart:3682])
#56 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#57 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#58 pc 0x3c5537 com.gogolook.rooney (StatefulElement.performRebuild [framework.dart:5133])
#59 pc 0x6a68af com.gogolook.rooney (StatefulElement._firstBuild [framework.dart:4690])
#60 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#61 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#62 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#63 pc 0x3c5537 com.gogolook.rooney (StatefulElement.performRebuild [framework.dart:5133])
#64 pc 0x6a68af com.gogolook.rooney (StatefulElement._firstBuild [framework.dart:4690])
#65 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#66 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#67 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#68 pc 0x3c5537 com.gogolook.rooney (StatefulElement.performRebuild [framework.dart:5133])
#69 pc 0x6a68af com.gogolook.rooney (StatefulElement._firstBuild [framework.dart:4690])
#70 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#71 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#72 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#73 pc 0x6a67e3 com.gogolook.rooney (ComponentElement._firstBuild [framework.dart:4690])
#74 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#75 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#76 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#77 pc 0x6a67e3 com.gogolook.rooney (ComponentElement._firstBuild [framework.dart:4690])
#78 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#79 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#80 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#81 pc 0x6a67e3 com.gogolook.rooney (ComponentElement._firstBuild [framework.dart:4690])
#82 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#83 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#84 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#85 pc 0x6a67e3 com.gogolook.rooney (ComponentElement._firstBuild [framework.dart:4690])
#86 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#87 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#88 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#89 pc 0x6a67e3 com.gogolook.rooney (ComponentElement._firstBuild [framework.dart:4690])
#90 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#91 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#92 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#93 pc 0x6a67e3 com.gogolook.rooney (ComponentElement._firstBuild [framework.dart:4690])
#94 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#95 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
#96 pc 0x8765db com.gogolook.rooney (ComponentElement.performRebuild [framework.dart:3682])
#97 pc 0x6a67e3 com.gogolook.rooney (ComponentElement._firstBuild [framework.dart:4690])
#98 pc 0x47bf53 com.gogolook.rooney (ComponentElement.mount [framework.dart:4944])
#99 pc 0x8a7a03 com.gogolook.rooney (Element.inflateWidget [framework.dart:3953])
```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.7.6, on macOS 13.2.1 22D68 darwin-arm64, locale zh-Hant-TW)
    • Flutter version 3.7.6 on channel stable at /Users/wunbinjhou/FlutterDevelopment/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 12cb4eb7a0 (7 weeks ago), 2023-03-01 10:29:26 -0800
    • Engine revision ada363ee93
    • Dart version 2.19.3
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/WunBinJhou/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • ANDROID_HOME = /Users/WunBinJhou/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.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.13+0-b1751.21-8125866)

[✓] Connected device (4 available)
    • Pixel 6 Pro (mobile)       • 1A021FDEE00462                       • android-arm64  • Android
      13 (API 33)
    • iPhone 14 Pro Max (mobile) • 9E25E67C-EEC2-43D8-BBCF-0FD8E042E644 • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS
      13.2.1 22D68 darwin-arm64
    • Chrome (web)               • chrome                               • web-javascript • Google
      Chrome 112.0.5615.121

[✓] HTTP Host Availability
    • All required HTTP hosts are available
```

</details>