-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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] Pushing to StatefulShellRoute from a top level route, the builder does not show #130406
Comments
Thank you for the report. I can see this issue on the latest package version In this case, flutter doctor -v (stable and master)[✓] Flutter (Channel stable, 3.10.6, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
• Flutter version 3.10.6 on channel stable at /Users/huynq/Documents/GitHub/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision f468f3366c (5 hours ago), 2023-07-12 15:19:05 -0700
• Engine revision cdbeda788a
• Dart version 3.0.6
• DevTools version 2.23.1
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-33, build-tools 32.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14E222b
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
[✓] VS Code (version 1.80.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.68.0
[✓] Connected device (3 available)
• RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64 • Android 11 (API 30)
• macOS (desktop) • macos • darwin-x64 • macOS 13.0.1 22A400 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 114.0.5735.198
[✓] Network resources
• All expected network resources are available.
• No issues found! [!] Flutter (Channel master, 3.13.0-3.0.pre.21, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
• Flutter version 3.13.0-3.0.pre.21 on channel master at /Users/huynq/Documents/GitHub/flutter_master
! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 47ba59c762 (3 hours ago), 2023-07-12 20:46:57 -0400
• Engine revision 1b1ccdd1f5
• Dart version 3.1.0 (build 3.1.0-302.0.dev)
• DevTools version 2.25.0
• If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-33, build-tools 32.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14E222b
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
[✓] VS Code (version 1.80.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.68.0
[✓] Connected device (3 available)
• RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64 • Android 11 (API 30)
• macOS (desktop) • macos • darwin-x64 • macOS 13.0.1 22A400 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 114.0.5735.198
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 1 category. |
Hi, |
Hi, |
Isn't this expected behavior? You should use Since the nested navigator that adds the shell is defined in the routes tree I would assume that it is required to use Is there a specific reason for you to use |
The reason is that i don't want to remove the back stack. When you use go instead of push you replace all the current stack of pages with a new page. |
I know. And guess thats also the reason why But you could rearrange your routes so that your shell route is a child of the other route. Then you can simply use |
@c0pp1ce Wow, Thank so much. As you mentioned i rearranged my routes and with |
This is not a desired solution for my usecase. What I'm dealing with is there are 2 roles. A user role will be shown the shell route as the first page, while an Admin role will first be shown a page where it contains the user's it has created and when a user is clicked then it'll show the shell route. So you can think of the admin having a layer before the shell route. Therefore, pushing the shell route from the admin page should show the shell route and when backed out, should go back to admin page. |
You can still rearrange you routes in order to achieve your desired behavior while using If you need some guidance, I could show you an example of a working solution. But since that is using query parameters instead of proper state management (for roles, users) I wont post it here (its simply quite messy 😄). Anyway, a more abstract way to get it done:
An example:
/// Assuming the StatefulShellRoute has two branches: /account, /other.
void branchRelativeGo(BuildContext context, String location) {
final String location = GoRouterState.of(context).location;
final parts = location.split("/");
/// Using contains so it works with query parameters.
final indexOfInitialBranchLocation = parts.indexWhere(
(element) => element.contains("account") || element.contains("other"),
);
/// Path to the shell. In the example either /app or /app/users
final shellPath = parts.removeRange(indexOfInitialBranchLocation, parts.length).join("/");
context.go("$shellPath$location");
} It then could be used like onTap: () => branchRelativeGo(context, "/account"); So you would need to specify the locations starting with the initial branch location. ProblemsThis approach, as can be seen already, does come with some boilerplate. Even more boilerplate code is required if there are sibling routes of the EditI do think this would be much easier to implement if popping pages would trigger the redirects. |
The adb shell 'am start -a android.intent.action.VIEW \
-c android.intent.category.BROWSABLE \
-d "http://example/menu"' \
com.example it removes the back stack and replaces all the current stack of pages with a new page (menu). |
thanka a lot, You saved my day |
@c0pp1ce How would you do it you wanted the backbutton to show when navigating from a shell route to a login screen that is at top level. You would have to use context.push and not context go right? And if you dont use GoRouter.optionURLReflectsImperativeAPIs = true; which is adviced against, the url wont be updated when doing context.push. Also I heard that context.push should be avoided alltogether. There is a lot of confusion around this for me. |
@patrikheinonen I think this is off-topic, I am unsure if it should be discussed here. Anyway, I would first ask why there is a need for a back button on a login page. But yes, you will need to make sure the stack of pages matches your needs - either through fitting route structure or by using push. |
@c0pp1ce I have some pages like :
now, I open app , splash page ->StatefulShellRoute |
@lizhuoyuan You have several options. What is the purpose of |
@c0pp1ce Most of the examples in go_router aren't enough to guide rearranging. I can't figure out how to handle the simple following case: screen A -> screen C screen C can be Take the example below. This will cause the error TypedGoRoute<ARoute>(
path: '/a',
routes: [
TypedGoRoute<BRoute>(
path: 'b',
routes: [
TypedGoRoute<CRoute>(path: 'c'),
]
),
TypedGoRoute<CRoute>(path: 'c')
]
) |
General approachYou should first decide if you actually need to use If that is the case you have two options. The first one would be to arrange the routes in a way that the parent-child relations enable the behaviour that you need. The second one would be to define multiple routes that display the same widget/screen. Concerning your specific problemI am not a huge fan of code generation. Your problem validates this opinion once again. Code gen is hard to get right after all. You tried to go with the second option in order to achieve the desired behaviour. Thats fine. More importantly it works without any problems when using However, I would try to do something like this: final cRoute = TypedGoRoute<CRoute>(path: 'c');
TypedGoRoute<ARoute>(
path: '/a',
routes: [
TypedGoRoute<BRoute>(
path: 'b',
routes: [
cRoute,
]
),
cRoute,
]
) |
@c0pp1ce thanks for the reply GoRoute(
path: '/a',
builder: (context, state) => APage(),
routes: [
GoRoute(
path: 'b',
builder: (context, state) => BPage(),
routes: [
GoRoute(
path: 'c',
builder: (context, state) => CPage(),
),
],
),
GoRoute(
path: 'c',
builder: (context, state) => CPage(),
),
],
), And when we wanna go to C from A, we use If they are true, then things get bloated very quickly |
Exactly. Yes, if you want to assign the paths to variables you would need to name them differently. Sadly, go_router does not seem to support relative routes which would make this even simpler. (#108177) |
@c0pp1ce the #139471 issue I just filed is kinda related to this one. I can't find a way to go to a route that's in a shell route, and it plays the transition animation of the route and the shell route. IMO, that supports the idea of pushing a route should push the |
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 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
Is there an existing issue for this?
Steps to reproduce
Expected results
The shell route should load the bottom navigation bar
Actual results
The bottom navigation bar isn't visible
Code sample
Code sample
Screenshots or Video
Screenshots / Video demonstration
Logs
Logs
[Paste your logs here]
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: