Repository: flutter
Issue: ModalRoute didPop throws Error: Failed assertion: 'entry.currentState == _RouteLifecycle.popping': is not true.
Labels: framework,f: routes,a: error message,has reproducible steps,P2,found in release: 2.10,found in release: 2.11,team-framework,triaged-framework

I've be using a pattern to pop a route with a result that seems to break with the change in the PR https://github.com/flutter/flutter/pull/94575. 

```dart
final route = ModalRoute.of(context)!;
final success = await serverRequest();
if (success) route.didPop(true);
```

I was using flutter version 2.5.3 before and the code above was working, but it started breaking when I upgraded to version 2.10.1.

It breaks when popping if pushed with `transitionDuration: Duration.zero`, or if transition duration is greater than 0 it allows popping but breaks when pushing again.
```dart
Navigator.of(context).push(
  RawDialogRoute(
    // it breaks when popping if transition duration is zero
    // it breaks on next push if transition duration is not zero
    transitionDuration: Duration.zero,
    pageBuilder: (context, _, __) => const OtherPage(),
  ),
)
```

<details>
<summary>exception</summary>

```
Unhandled Exception: 'package:flutter[/src/widgets/navigator.dart]()': Failed assertion: line 5021 pos 12: 'entry.currentState == _RouteLifecycle.popping ||
package:flutter/…/widgets/navigator.dart:5021
          (entry.hasPage && entry.currentState.index < _RouteLifecycle.pop.index)': is not true.
#0      _AssertionError._doThrowNew (dart:core-patch[/errors_patch.dart:51:61]())
#1      _AssertionError._throwNew (dart:core-patch[/errors_patch.dart:40:5]())
#2      NavigatorState.finalizeRoute
package:flutter/…/widgets/navigator.dart:5021
#3      OverlayRoute.didPop
package:flutter/…/widgets/routes.dart:74
#4      TransitionRoute.didPop
package:flutter/…/widgets/routes.dart:262
#5      LocalHistoryRoute.didPop
package:flutter/…/widgets/routes.dart:669
```
</details>

Is there other way of achieving the same result? I use this pattern because I can not guarantee that the route will be the top one when I am popping it.

I made a minimal reproducible example: https://gist.github.com/lslv1243/2b1004e92494fffeb7e167e7e057c3cb

<details>
<summary>working version (2.5.3) flutter doctor -v</summary>

```
[✓] Flutter (Channel stable, 2.5.3, on macOS 12.2 21D49 darwin-arm, locale pt-BR)
    • Flutter version 2.5.3 at /Users/leonardosilva/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (4 months ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/leonardosilva/Library/Android/sdk
    • Platform android-31, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 13.1, Build version 13A1030d
    • 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-7281165)

[✓] VS Code (version 1.64.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.34.0

[✓] Connected device (4 available)
    • Mi A2 (mobile)              • d73165                                   • android-arm64  • Android 10 (API 29)
    • iPhone de Leonardo (mobile) • ac197a55a52fbad3d364054a4c99dbe29ed46b23 • ios            • iOS 15.2.1 19C63
    • macOS (desktop)             • macos                                    • darwin-arm64   • macOS 12.2 21D49 darwin-arm
    • Chrome (web)                • chrome                                   • web-javascript • Google Chrome 98.0.4758.80

• No issues found!
```
</details>

<details>
<summary>not working version (2.10.1) flutter doctor -v</summary>

```
[✓] Flutter (Channel stable, 2.10.1, on macOS 12.2 21D49 darwin-arm, locale pt-BR)
    • Flutter version 2.10.1 at /Users/leonardosilva/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision db747aa133 (30 hours ago), 2022-02-09 13:57:35 -0600
    • Engine revision ab46186b24
    • Dart version 2.16.1
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/leonardosilva/Library/Android/sdk
    • Platform android-31, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.1)
    • 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-7281165)

[✓] VS Code (version 1.64.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.34.0

[✓] Connected device (4 available)
    • Mi A2 (mobile)              • d73165                                   • android-arm64  • Android 10 (API 29)
    • iPhone de Leonardo (mobile) • ac197a55a52fbad3d364054a4c99dbe29ed46b23 • ios            • iOS 15.2.1 19C63
    • macOS (desktop)             • macos                                    • darwin-arm64   • macOS 12.2 21D49
      darwin-arm
    • Chrome (web)                • chrome                                   • web-javascript • Google Chrome 98.0.4758.80

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
```
</details>