-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[go_router] push
and pushReplacement
are not in the correct ShellRoute
#120665
Comments
Hi @ValentinVignal, does the video below capture the issue clearly? (Your video wasn't uploaded, unfortunately) videoScreen.Recording.2023-02-14.at.10.49.30.mov |
Oh no, sorry for that. I edited the issue to re-upload it.
But yes, your video shows the issue clearly, thanks! |
Thanks for the confirmation. The issue is reproducible using the code sample in #120665 (comment) Labeling for further investigation. flutter doctor -v
|
This could be related to other issues with |
Thanks to this comment by @patrikheinonen, I think your issue @valentinvigna, might just be solved as well, try this code below Btw the blue box appears at the very top right, due to no safeArea widget. import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
void main() {
runApp(const MyApp());
}
// private root navigator
final _rootNavigatorKey = GlobalKey<NavigatorState>();
final router = GoRouter(
initialLocation: '/out-shell-0',
navigatorKey: _rootNavigatorKey,
routes: [
GoRoute(
parentNavigatorKey: _rootNavigatorKey,
path: '/out-shell-0',
builder: (context, state) {
return const Screen(name: 'Out shell 0');
},
),
GoRoute(
parentNavigatorKey: _rootNavigatorKey,
path: '/out-shell-1',
builder: (context, state) {
return const Screen(name: 'Out shell 1');
},
),
ShellRoute(
parentNavigatorKey: _rootNavigatorKey,
routes: [
GoRoute(
path: '/in-shell-0',
builder: (context, state) {
return const Screen(name: 'In shell 0');
},
),
GoRoute(
path: '/in-shell-1',
builder: (context, state) {
return const Screen(name: 'In shell 1');
},
),
],
builder: (context, state, child) {
return Shell(child: child);
},
),
],
);
class Shell extends StatelessWidget {
const Shell({
required this.child,
super.key,
});
final Widget child;
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Material(
color: Colors.blue,
child: Text('In Shell'),
),
Expanded(
child: child,
),
],
);
}
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: router,
);
}
}
class Screen extends StatelessWidget {
const Screen({
required this.name,
super.key,
});
final String name;
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
children: [
Text(name),
const _Tile(route: '/in-shell-0'),
const _Tile(route: '/in-shell-1'),
const _Tile(route: '/out-shell-0'),
const _Tile(route: '/out-shell-1'),
],
),
);
}
}
class _Tile extends StatelessWidget {
const _Tile({
required this.route,
Key? key,
}) : super(key: key);
final String route;
@override
Widget build(BuildContext context) {
final router = GoRouter.of(context);
return ListTile(
title: Text(route),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
TextButton(
onPressed: () {
router.go(route);
},
child: const Text('go'),
),
TextButton(
onPressed: () {
router.push(route);
},
child: const Text('push'),
),
TextButton(
onPressed: () {
router.pushReplacement(route);
},
child: const Text('pushReplacement'),
),
],
),
);
}
}
|
@JohnF17 I shouldn't have to specify the root navigator key, I think this issue should remain open. Thank you for the work around though |
Glad it could help, though @ValentinVignal, might I ask why is using a root navigator looked down upon?, i've had others say this as well 👀. |
It is redundant. When creating the |
Hmm that is true indeed, GoRouter has to use the navigator of its closest parent by default, besides being redundant though it hasn't got any performance issues I believe, so this workaround might be best till this issue gets addressed. P.s. I've got a question around when to use StatefulShellRoute and ShellRoute, any articles or stackoverflow posts or if anyone would like to explain, please do. |
This pr refactor RouteMatchList to be a tree structure. Added a common base class RouteMatchBase. It is extended by both RouteMatch and ShellRouteMatch. The RouteMatch is for GoRoute, and is always a leaf node The ShellRouteMatch is for ShellRouteBase, and is always and intermediate node with a list of child RouteMatchBase[s]. This pr also redo how push is processed. Will add a doc explain this shortly. This is a breaking change, will write a migration guide soon. fixes flutter/flutter#134524 fixes flutter/flutter#130406 fixes flutter/flutter#126365 fixes flutter/flutter#125752 fixes flutter/flutter#120791 fixes flutter/flutter#120665 fixes flutter/flutter#113001 fixes flutter/flutter#110512
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
This pr refactor RouteMatchList to be a tree structure. Added a common base class RouteMatchBase. It is extended by both RouteMatch and ShellRouteMatch. The RouteMatch is for GoRoute, and is always a leaf node The ShellRouteMatch is for ShellRouteBase, and is always and intermediate node with a list of child RouteMatchBase[s]. This pr also redo how push is processed. Will add a doc explain this shortly. This is a breaking change, will write a migration guide soon. fixes flutter/flutter#134524 fixes flutter/flutter#130406 fixes flutter/flutter#126365 fixes flutter/flutter#125752 fixes flutter/flutter#120791 fixes flutter/flutter#120665 fixes flutter/flutter#113001 fixes flutter/flutter#110512
Steps to Reproduce
flutter run
on the code sample (see "Code sample" section below)There are 4 pages. 2 of them are in a
ShellRoute
while the 2 others are outsidego
, notice that everything works finepush
and/orpushReplacement
.ShellRoute
is off (You can see a "Shell" blue box on tap). When pushing a page, the "Shell" blue box doesn't disappear/appear when it should, it remains in the current state (shown or hidden).Expected results:
When pushing to a route
Actual results:
The blue box "Shell" remains hidden/shown and is not updated.
Code sample
Or you can checkout https://github.com/ValentinVignal/flutter_app_stable/tree/go-router/push-and-push-replacement-do-not-update-shell-route
Logs
Video
Screen.Recording.2023-02-14.at.2.39.51.PM.mov
The text was updated successfully, but these errors were encountered: