Repository navigation
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Use case
Our app consists of multiple modules. As we don't know which module is used by our users we need to create the StatefulShellBranches for our modules during runtime to preserve the state of each module and to also be able to navigate between them.
We discovered that it is possible to add new StatefulShellBranches to the StatefulShellRoute.indexedStack during runtime but they are never considered anymore during the runtime because the method "_branchLocation" of class "StatefulNavigationShellState" is only called once during the initialization. Therefore the newly added StatefulShellBranches is never added to the "_branchLocations" map and therefore the branches cannot be used.
We fixed it for our purpose by calling the method "_branchLocation" in the "build" method of the "StatefulNavigationShellState" class.
@override Widget build(BuildContext context) { final List<Widget> children = route.branches .map((StatefulShellBranch branch) => _BranchNavigatorProxy( key: ObjectKey(branch), branch: branch, navigatorForBranch: (StatefulShellBranch b) => _branchNavigators[b.navigatorKey])) .toList(); for(StatefulShellBranch branch in route.branches){ _branchLocation(branch); } return widget.containerBuilder(context, widget, children); }
It would be benefical to have a real solution for adding StatefulStateBranches during runtime.
Proposal
Add the newly added StatefulShellBranches during runtime to the "_branchLocations" map.
Activity
chutuananh2k commentedon Apr 24, 2024
Any progress in this issues? I face the same problem.
@matthiaslarisch Would you mind to share an example of how to dynamic add branch at runtime?
NorbertSzydlowski commentedon May 13, 2024
I have the same problem. Any advice? @matthiaslarisch
dleurs commentedon Sep 9, 2024
Any update ?
Current code of my project, with similar issue : https://github.com/dleurs/web_tab_nav
This question in stackoverflow : https://stackoverflow.com/questions/78964912/flutter-gorouter-build-tab-system-navigation-like-web-browser
JulienElkaim commentedon Oct 13, 2024
Any updates? I would love to see this feature as well.
bambinoua commentedon Jan 14, 2025
@matthiaslarisch, @dleurs, @JulienElkaim
I think you can add new branches (=router configuration) dynamically.
Please look at this GoRouter example.
andrei-toterman commentedon Jan 17, 2025
@bambinoua that example shows that you are allowed to dynamically add
RouteBases to theRounterConfig'sroutes. What we'd like to see is the capability to addStatefulShellBranches toStatefulShellRoute'sbranches. In that example, state is not preserved for each route.matl-swissas commentedon Mar 14, 2025
I have created a Pull Request that fixes this issue flutter/packages#8863
matl-swissas commentedon Mar 19, 2025
see last comment on flutter/packages#8863
github-actions commentedon Apr 2, 2025
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
flutter doctor -vand a minimal reproduction of the issue.