Repository: flutter
Issue: Android system back button with nested Navigator inside GoRouter unexpected navigator is used
Labels: platform-android,framework,f: routes,has reproducible steps,P2,team-android,triaged-android,found in release: 3.19,found in release: 3.21

### Steps to reproduce

1. Run the code
2. Copy the actions on the video

### Expected results

When clicking android system button it should take the nearest navigator on the tree from the current screen as it is done on the iOS platform

### Actual results

But when we using android system back button we face the problem, that GoRoute's navigator is used to pop, instead of deeper one, which was created by us

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends HookWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    final goRouter = useMemoized(
      () => GoRouter(
        initialLocation: '/1',
        routes: [
          GoRoute(
            path: '/1',
            builder: (context, state) => Navigator(
              onPopPage: (route, result) => route.didPop(result),
              pages: const [
                MaterialPage(
                    child: Screen(
                  text: '1',
                )),
              ],
            ),
          ),
        ],
      ),
    );
    return MaterialApp.router(
      routerConfig: goRouter,
    );
  }
}

class Screen extends StatelessWidget {
  const Screen({super.key, required this.text});

  final String text;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              text,
            ),
            ElevatedButton(
              onPressed: () {
                Navigator.of(context).push(
                  MaterialPageRoute(
                    builder: (context) => Screen(text: '$text nested'),
                  ),
                );
              },
              child: const Text('go to the nested page'),
            ),
            ElevatedButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: const Text('go back'),
            ),
          ],
        ),
      ),
    );
  }
}
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

https://github.com/flutter/flutter/assets/52509435/1b74d166-a728-4719-9648-5b299de199a3

https://github.com/flutter/flutter/assets/52509435/111612dc-685a-43ca-a259-29caa2497fd8


</details>


### Logs

<details open><summary>Logs</summary>

```console
not applicable
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.2, on macOS 14.4 23E214 darwin-arm64, locale en-PL)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] IntelliJ IDEA Community Edition (version 2023.2.5)
[✓] VS Code (version 1.87.1)
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!```

</details>