-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listd: api docsIssues with https://api.flutter.dev/Issues with https://api.flutter.dev/found in release: 3.19Found to occur in 3.19Found to occur in 3.19found in release: 3.22Found to occur in 3.22Found to occur in 3.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packageThe go_router packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Steps to reproduce
- go_router: v12.1.3
- Launch sample
- Press 'Go to page B' button
- Press 'Go Page A and Show dialog' button
- 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
Code sample
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'),
),
),
],
),
);
}
}Flutter Doctor output
Doctor output
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!dkbast, eli1stark, Tetr4 and rorystephenson
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listd: api docsIssues with https://api.flutter.dev/Issues with https://api.flutter.dev/found in release: 3.19Found to occur in 3.19Found to occur in 3.19found in release: 3.22Found to occur in 3.22Found to occur in 3.22has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: go_routerThe go_router packageThe go_router packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team