Repository: flutter
Issue: [go_router]: dialogs and bottom sheets are not shown after calling go or goNamed.
Labels: d: api docs,package,has reproducible steps,P2,p: go_router,team-go_router,triaged-go_router,found in release: 3.19,found in release: 3.22

### Steps to reproduce

1. go_router: v12.1.3
3. Launch sample
4. Press 'Go to page B' button
5. Press 'Go Page A and Show dialog' button
6. Dialog is not shown

It seems that the go_router API is not truly synchronous, as stated in the documentation, which can lead to issues like this. The asynchronous behavior is hidden behind the API, and the client assumes that it's synchronous. In this case, it seems a race condition occurs between `goNamed` and `showDialog`.

Adding some arbitrary delay between calls fixes the issue, but this is not a great solution because you can never know what is a sufficient time needed to await `go` and `goNamed` to avoid the issue on all devices and platforms.

### Expected results

Dialog must be shown.

### Actual results

Dialog is not shown.

### Code sample

<details open><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

final router = GoRouter(
  routes: [
    GoRoute(
      name: 'A',
      path: '/',
      builder: (_, __) => const PageA(),
    ),
    GoRoute(
      name: 'B',
      path: '/B',
      builder: (_, __) => const PageB(),
    ),
  ],
);

void main() => runApp(const App());

class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      routerConfig: router,
    );
  }
}

class PageA extends StatelessWidget {
  const PageA({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Center(
            child: TextButton(
              onPressed: () {
                context.pushNamed('B');
              },
              child: const Text('Go to page B'),
            ),
          ),
        ],
      ),
    );
  }
}

class PageB extends StatelessWidget {
  const PageB({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey,
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Center(
            child: TextButton(
              onPressed: () {
                final ctx = router.routerDelegate.navigatorKey.currentContext!;
                ctx.goNamed('A');
                showDialog(
                  context: ctx,
                  builder: (_) => const AlertDialog(
                    title: Text('Dialog Title'),
                    content: Text('This is my content'),
                  ),
                );
              },
              child: const Text('Go Page A and Show dialog'),
            ),
          ),
        ],
      ),
    );
  }
}
```

</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.16.7, on macOS 14.2.1 23C71 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.87.2)
[✓] Connected device (4 available)
[✓] Network resources

• No issues found!
```

</details>