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] 5.2.1 goRouterState.path & goRouterState.name giving null value in route builders if sub routes in ShellRoute and control not going on defined route builder #116516
Comments
@hpomgithub |
@darshankawar |
Flutter (Channel stable, 3.3.9, on macOS 12.4 21F79 darwin-arm, locale en-IN) |
Thanks for the update. stable, master flutter doctor -v
|
I don't think there is a reasonable value to put into name and path since the ShellRoute does not have a name and path. If the goal is to know which sub route has the match, we should add some new property in the GoRouterState to expose that. |
Hello @chunhtai , This was working fine in the version 5.0.1. The point I would like to bring into you notice is that it is not responding when a particular sub-route(/a) defined in Shell Route is called. To confirm this we have logged the values. As here you can see that when we call '/a' path then that particular go route builder function (in sub route of shell route) must be called, but it is not getting called and to know what's fishy we have logged the state.name and state.path in shell route builder which is giving us null. So this means internally name and path are not getting initialised when that particular '/a' is called. |
I did see the log gets printed out
This is the code i was using import 'package:go_router/go_router.dart';
import 'package:flutter/material.dart';
final GlobalKey<NavigatorState> _rootNavigatorKey =
GlobalKey<NavigatorState>(debugLabel: 'root');
final GlobalKey<NavigatorState> _shellNavigatorKey =
GlobalKey<NavigatorState>(debugLabel: 'shell');
void main() {
// usePathUrlStrategy();
runApp(ShellRouteExampleApp());
}
/// An example demonstrating how to use [ShellRoute]
class ShellRouteExampleApp extends StatelessWidget {
/// Creates a [ShellRouteExampleApp]
ShellRouteExampleApp({Key? key}) : super(key: key);
final GoRouter _router = GoRouter(
navigatorKey: _rootNavigatorKey,
initialLocation: '/a',
routes: <RouteBase>[
GoRoute(
path: '/new',
builder: (a, b) => Text('new'),
parentNavigatorKey: _rootNavigatorKey),
/// Application shell
ShellRoute(
navigatorKey: _shellNavigatorKey,
pageBuilder:
(BuildContext context, GoRouterState goRouterState, Widget child) {
print(
"State name in Builder of shell builder:-${goRouterState.name}");
print(
"State location in Builder of shell builder:-${goRouterState.location}");
print(
"State path in Builder of shell builder:- ${goRouterState.path} ");
return MaterialPage(
child: Scaffold(body: child), maintainState: true);
},
routes: <RouteBase>[
/// The first screen to display in the bottom navigation bar.
GoRoute(
name: 'a',
path: '/a',
builder: (BuildContext, goRouterState) {
print(
"State name in Builder of route:-${goRouterState.name}");
print(
"State location in Builder of route:-${goRouterState.location}");
print(
"State path in Builder of route:- ${goRouterState.path}");
return Text("a");
})])
]
);
@override
Widget build(BuildContext context) {
return MaterialApp.router(routerConfig: _router,);
}
}
What is working in 5.0.1? The name and path? or the logging in sub-route? |
Hi @chunhtai Everything was working in 5.0.1, but issue came in all versions of 5.1.10 - 5.2.1. But let me check it using the way you did. |
Hi @chunhtai , |
yes it is expected. The child represent the subtree of the sub-route. if you throw it away, there is no reason to build it |
Hi @chunhtai , |
take a look at this flutter/packages#2650 |
Hi @chunhtai , |
@chunhtai |
adding another bug to this issue: A workaround (currently produces final route = GoRouter.of(context).routerDelegate.matches.last.route;
final routeName = route is GoRoute ? route.name : null; |
The text was updated successfully, but these errors were encountered: