-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[go_router] Add titleBuilder to GoRoute and GoRouterState
#5701
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] Add titleBuilder to GoRoute and GoRouterState
#5701
Conversation
|
This seems to be a very limited use case, I think the root problem is that the shellroute doesn't have information about the current child. I think this is something we should figure out a better API to expose such thing. WDYT? |
|
@chunhtai yes that would work, though I wasn't able to come up with a more generic solution without casting. Perhaps a solution could involve generics on the GoRoute class, but I'm not sure how that would be done without loosing the types in the routes list |
|
I experimented with having adding generic type that the custom data builder can return. it is possible, but i had to add generics to nearly every go_router class. (Probably not what we want, but what are your thoughts?) The result is really good though, the |
|
In 0ddddb6, I converted the title builder to extensions, similar to Flutter's theme extensions Usage: GoRoute(
path: 'b',
extensions: <GoRouterStateExtensionBuilder>[
(_, __) => const RouteTitleExtension('B'),
(_, __) => const OtherCustomDataExtension('B.2'),
],
builder: (BuildContext context, GoRouterState state) {
return const Scaffold(
body: Text('Screen 2'),
);
},
)
class RouteTitleExtension
implements GoRouterStateExtension<RouteTitleExtension> {
const RouteTitleExtension(this.title);
final String title;
}
GoRouterState.of(context).extension<RouteTitleExtension>(context).title |
|
New PR opened based on 13.0.0 #5736 |
This is something I hacked together, bringing the
titleBuilderfromauto_routetogo_router. I suspect it will need some changes, as I am not familiar with the internals of GoRouter.If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.
Pre-launch Checklist
dart format.)[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style.///).If you need help, consider asking for advice on the #hackers-new channel on Discord.