Repository navigation
Open
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterp: go_routerThe go_router packageThe go_router packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
Description
Use case
For custom transitions there's already the possibility to declare a GoRoute with a pageBuilder. In cases where the same custom transition is needed for every page in the app, this method becomes repetitive and redundant.
GoRouter(
routes: [
GoRoute(
path: '/',
pageBuilder: (context, state) => MyCustomTransitionPage(
child: RootPage(),
),
routes: [
GoRoute(
path: 'page2',
pageBuilder: (context, state) => MyCustomTransitionPage(
child: Page2(),
),
),
GoRoute(
path: 'page3',
pageBuilder: (context, state) => MyCustomTransitionPage(
child: Page3(),
),
),
GoRoute(
path: 'page4',
pageBuilder: (context, state) => MyCustomTransitionPage(
child: Page4(),
),
),
],
),
],
);Proposal
To solve this issue it would be really great to add a custom pageBuilder to GoRouter constructor and use it (if present) as the default pageBuilder for every GoRoute that only declares a builder
GoRouter(
pageBuilder: (context, state, child) => MyCustomTransitionPage(
child: child,
),
routes: [
GoRoute(
path: '/',
builder: (context, state) => RootPage(),
routes: [
GoRoute(
path: 'page2',
builder: (context, state) => Page2(),
),
GoRoute(
path: 'page3',
builder: (context, state) => Page3(),
),
GoRoute(
path: 'page4',
builder: (context, state) => Page4(),
),
],
),
],
);Reacted by Francesco Iapicca, mono — Masayuki Ono, janknips, Pascal Welsch, Trey Dev, harkairt, Sheena, Wessel van Dam, Ercan Tomac, TiM and 35 more
Reacted by Razi Kallayi
Reacted by Razi Kallayi
Reacted by Razi Kallayi
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to FlutterA detailed proposal for a change to Flutterp: go_routerThe go_router packageThe go_router packagepackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem teamTriaged by Ecosystem team
Type
Projects
- StatusShow more project fieldsNo status
Activity
exaby73 commentedon Oct 11, 2022
Hello @Skogsfrae. Can you provide a complete and minimal, reproducible example of the current behavior so that I may verify the issue?
iapicca commentedon Oct 11, 2022
@Skogsfrae I really like the idea it makes the code much cleaner , testable and reduce the risk of errors
@exaby73 I'm confused, the proposal looks super clear to me
Skogsfrae commentedon Oct 11, 2022
Hi @exaby73
This is not a bug, but a feature proposal.
I provided a minimal snipped of the current behaviour in the Use Case section and a proposal of improvement in the Proposal section.
I didn't provide a runnable snippet of code to keep the focus on GoRouter interface. If still needed let me know, I'll try to write something more detailed.
passsy commentedon Dec 19, 2022
This would be especially helpful when using
WidgetsApp, notMaterialApp. In that case,go_routerdefaults toNoTransitionPagewhich does nothing. It's annoying to overwrite it for every Route.ValentinVignal commentedon Mar 17, 2023
What would also be nice would be to be able to give a default page builder to a
GoRouteor aShellRouteso it is applied to all its nested children.jeroen-meijer commentedon Sep 11, 2023
Any progress on this?
shivamkj commentedon Mar 27, 2024
Go router uses default page transaction present in the theme data, so If someone wants a custom transaction for all routes they can just provide it to the root material app. Below is a minimal example which use slide animation for all routes transaction. After this you just continue to
builderinstead ofpageBuilderand whatever page transaction you have provided in theme, will be used all over the app.