Repository: flutter
Issue: Popped route still exist in remove predicate while using `navigator.pushAndRemoveUntil` after await `navigator.push`
Labels: framework,f: routes,P2,team-framework,triaged-framework

### Steps to reproduce

1. Run the sample code
2. Click the middle button
3. Check console output

### Expected results

flutter: route: page_two

### Actual results

flutter: route: page_three

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});


  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  void _onPressed(BuildContext context) async {
    final navigatorState = Navigator.of(context);
     navigatorState.push(
      MaterialPageRoute(
        builder: (_) => const PageOne(),
        settings: const RouteSettings(name: 'page_one'),
      ),
    );
     navigatorState.push(
      MaterialPageRoute(
        builder: (_) => const PageTwo(),
        settings: const RouteSettings(name: 'page_two'),
      ),
    );
     navigatorState.push(
      MaterialPageRoute(
        builder: (_) => const PageThree(),
        settings: const RouteSettings(name: 'page_three'),
      ),
    );
    //Current route is [page_one, page_two, page_three]
    await Future.delayed(const Duration(seconds: 1));
    navigatorState.pop();
    //Current route is [page_one, page_two]
    navigatorState.pushAndRemoveUntil(
      MaterialPageRoute(
        builder: (_) => const PageOne(),
        settings: const RouteSettings(name: 'page_one'),
      ),
      (route) {
        // Expect output should be "route: page_two", but actual is "route: page_three",
        print('route: ${route.settings.name}');
        return true;
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      ),
      body: Builder(builder: (context) {
        return Center(
          child: TextButton(
            onPressed: () => _onPressed(context),
            child: const Text("Click Me", style: TextStyle(fontSize: 30),),
          ),
        );
      }),
    );
  }
}

class PageOne extends StatelessWidget {
  const PageOne({super.key});

  @override
  Widget build(BuildContext context) {
    return const ColoredBox(color: Colors.blue);
  }
}

class PageTwo extends StatelessWidget {
  const PageTwo({super.key});

  @override
  Widget build(BuildContext context) {
    return const ColoredBox(color: Colors.red);
  }
}

class PageThree extends StatelessWidget {
  const PageThree({super.key});

  @override
  Widget build(BuildContext context) {
    return const ColoredBox(color: Colors.yellow);
  }
}

```

</details>


### Screenshots or Video

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


### Logs

<details open><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.24.1, on macOS 14.6.1 23G93 darwin-arm64, locale zh-Hans-CN)
    • Flutter version 3.24.1 on channel stable at /Users/tangkailiang/fvm/versions/3.24.1
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5874a72aa4 (3 weeks ago), 2024-08-20 16:46:00 -0500
    • Engine revision c9b9d5780d
    • Dart version 3.5.1
    • DevTools version 2.37.2
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /Users/tangkailiang/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15F31d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1)
    • 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.11+0-17.0.11b1207.24-11852314)

[✓] IntelliJ IDEA Ultimate Edition (version 2024.2)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 81.1.3
    • Dart plugin version 242.20629

[✓] VS Code (version 1.92.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.94.0

[✓] Connected device (5 available)
    • iPhone (mobile)                 • 00008120-001451993C90A01E            • ios            •
      iOS 17.5.1 21F90
    • iPhone 15 (mobile)              • 43BA2B9D-D219-4321-AD2D-EBAB3CC7B95E • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-17-5 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   •
      macOS 14.6.1 23G93 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         •
      macOS 14.6.1 23G93 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript •
      Google Chrome 128.0.6613.120

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>