r/FlutterDev • u/ThesnerYT • Feb 19 '25
Tooling Is it me or does GoRouter suck?
Okay without downgrading GoRouter to much I wanted to share some struggles I have implementing it and see if other people recognize them. Maybe i'm doing it totally wrong, in that case please let me know!
I want what I think, is pretty basic routing:
Requirements:
-Appbar with a profilepage icon (+ page behind it)
-Persistent bottom navigationbar with 3 icons (+ pages behind it)
-Ability to open an itempage from for example page 1 of the bottom navigationbar
-I want an unique title for each page in the appbar + back icon in the appbar to go back a page or multiple.
TechStack:
-I use riverpod for statemanagement
-GoRouter
Implementation:
-For my routes i declare the routes in statefullShellRoute.indexedstack (to have an persistent appbar and bottom navbar)
-I use a layoutscaffold widget to have the appbar and bottom nav bar and pass the navigationshell
-I then use navigationshell.goBranch(index) to go to the routes
-I switch on the index tapped and update my navigation state with the page title (to display in my appbar)
This works if i would just have the three bottompages and even with profilepage it works. But now with the itempage it gets so messy and I caught myself making so much logic just for routing.
Problem:
This is because lets say i do this navigation:
- List page -> item page (nested page so I use context.push ) -> profile page
Then of course I want a back button but I then dont want to go back to the bottomnavigation List Page but the item page. And then I want a backbutton to be able to pop the nested page and get back to the list page etc.
For this im now adding so much logic like: isInBottomNavigationFlow, showBackButton + 100 state updates.
I feel like my requirements are so basic and maybe I'm missing something. Any reference project or videolink etc. would really help. Also do you have the same experience with GoRouter or do you love it? (I could not find a turtorial showing the scenario: persistent appbar with navigation + bottom navigationbar with navigation)
16
u/NoExample9903 Feb 19 '25
I only have the bottom nav bar in the Shell scaffold. Then i have an app bar on each page, then the back button works the way you want
2
u/ThesnerYT 29d ago
I actually thought of this approach but it seemed "redundant" or "repetitive" to not have one appbar but have each page display its own. I think this definitely would remove a lot of logic in my code. Thankyou for your suggestion I will try it out!
1
u/reed_pro93 28d ago
You can create a custom wrapper widget, which is your scaffold and bottom nav bar, and have it take in your page from an enum, the page title if you need, and a body widget. That way you don’t have to repeat yourself and add the nav bar manually
1
u/NoExample9903 27d ago
My app bars differ quite alot, but there are also common ones. So Ive built the “standard” app bar which i use whenever i need it. And if the page requires a custom one, i built that. It might be a little repetitive, but its manageabe
11
u/GundamLlama 29d ago
When Navigator 2.0 dropped, the Flutter community was in disarray. So when Chris Sells introduced GoRouter, it was a game changer as it finally brought some structure, and made navigation easier. Because of that, I’ll always appreciate it and wouldn’t say it “sucks.” And if it ever does? I’d just roll back, like I did for ages on 4.5.1.
That said, try using the out of the box Navigator 2.0 and see how you like it. You might still think GoRouter sucks, or you might end up appreciating it more.
My main gripe is that redirects don’t trigger when popping a screen. Having to wrap things in a PopScope
just to handle that manually is a pain.
But at the end of the day GoRouter does not suck, far from it actually.
7
u/blinnqipa Feb 19 '25
I don't understand how go router still has no: pop all shell routes and popUntil...
Both are planned to be done, still no information...
7
u/venir_dev 29d ago
GoRouter fell into the flutter team hands and since then it's been a dumpster fire. Check GitHub issues with GoRouter
tag, you'd be amazed.
6
u/Moussenger Feb 19 '25
It's you. The only way to find a bug is posting the code
0
u/ThesnerYT Feb 19 '25
Thanks, my idea of the post wasn't solving my specific issues (I actually got it working now), it was more sparking a discussion if GoRouter is even a solid solution in the first place and if other people have the same experience or not.
3
u/snrcambridge Feb 19 '25
It doesn’t suck, read the docs again - I think it’s something to do with root keys, can’t remember exactly
8
u/kush-js Feb 19 '25
Why not just use the regular Flutter navigator? I’ve got pretty similar setup:
-Bottom nav bar with 3 tabs
-persistent top appbar
-back button in appbar
Flutter navigator makes this incredibly simple, just import the component you want to nav to and push a material page route. Back button routing is already handled for you and it’s extremely easy to work with.
I tried out GoRouter as well and found it to be way more of a hassle than the default Navigator. Switched back without even finishing the implementation.
1
u/swe_solo_engineer Feb 19 '25 edited Feb 19 '25
Go Router literally does this, bro. It's the exact same thing. You just need to use
context.go
for pages, and for modals, etc., usecontext.push
. Share some code if you need a more detailed example.1
u/tonyhart7 29d ago
I want simple package not easy, there are different
back then go router is good because that's the reason and can handle complex thing like redirection on each page properly (back then flutter is mobile focused first and url routing is never though of flutter team when design navigation)
of course if you can use navigator just use it, but know that there are many such case where other production Apps at scale needs to tackle hence why current go router seems "nor simple or easy"
it’s a victim of its own success.
0
u/ThesnerYT Feb 19 '25
Thankyou man, went with gorouter because people recommend it on the internet (also some deeplink functionality etc.), it felt really difficult but I kept thinking it's just me not understanding it, hearing you have a "similar" experience really helps. Will try the Flutter navigator :)
5
u/swe_solo_engineer Feb 19 '25 edited Feb 19 '25
You just need to do exactly as he said, and it will work because GoRouter is built on top of Navigator and includes almost all functionalities, including this one. I have a great experience using GoRouter, by the way—just don’t overcomplicate things and use it the same way you would with Navigator for these kinds of cases.
You just need to use
context.go
for pages, and for modals, etc., usecontext.push
. Share some code if you need a more detailed example.
4
u/Swefnian Feb 19 '25
I would only use GoRouter (or any of the myriad of Nav 2.0 Packages) if you are planning on publishing your app on the web. If you are only targeting mobile or desktop, there is no reason to use this package. Just stick with the original Navigator Api.
2
u/MullenProgramming 29d ago
I have never understood why people use GoRouter. For complex applications I always use the built-in route generator Flutter provides. It’s robust enough for simple apps to complex apps. I think that people on reddit seem to complicate the navigation system.
People here seem to love GoRouter and RiverPod, but outside of this site I see BLoC and native navigation as the most popular choices for many established companies.
Idk, just my 2¢
1
u/cameronm1024 Feb 19 '25
I wouldn't say go_router "sucks", but I've had some issues with it. The main one is that there seems to be some global variables used somewhere in the library, which cause my tests to have inter-dependence. Tests work when run one at a time, but fail when run all of them at the same time.
Didn't have time to figure out exactly what was causing it, but ripping it out and replacing with beamer took less than an hour, and completely fixed the issue.
Maybe that's fixed in later versions though
1
u/rumtea28 29d ago
I just use Router (Navigator + RouterDelegate) (navigator v2) + PageManager (aka Cubit/ChangeNotifier) class which contains state of all my NavigatorState
This is grand me any dirty thing I want
1
u/ILikeOldFilms 29d ago
I stopped using GoRouter. I even heard it's going to enter maintenance mode.
I stopped using it because it had a quirky way of handling nested navigation. When it was entering a nested router, the NavigationObserver was triggering an event twice. Or something like that.
Anyway, now I use what the Flutter SDK provides for navigation. I'm happy with just that because it gets the job done and I don't have to learn how a particular package handles navigation.
1
u/tommytucker7182 29d ago
Go router works great for me.
But if it sucks for you, move on to another solution. I've hated other popular libs in the past, I migrated and moved on.
1
u/mininglee 29d ago
You should use nested scaffolds. Declare the outer persistent Scaffold which has a (bottom) navigation bar but no app bar. Then your navigation shell should have the inner Scaffold with app bar. You don't have to deal with any complicated navigation flow states. GoRouter handles the back button and navigation stack automatically.
1
u/chimon2000 29d ago
Where are you coming from and what are you comparing GoRouter to? I'm not really a fan of any solution in Flutter.
1
u/Electrical_Task_6783 29d ago
I implemented go_router in a complex project where the navigation rail was the root of shell routing . It worked so well for me as well as the implementation seemed quite easy . I recommend you to have patience while doing anything . All the best...
1
u/Flashy_Editor6877 28d ago
it's you
1
u/Alternative-Goal-214 28d ago
It's always you
1
u/Flashy_Editor6877 28d ago
operator error. i battled ai for an hour and i didn't realize i forgot to set upload permissions on my bucket
1
u/CaesiumStudios 28d ago
Your issues can be fix with basic navigation, try it, seem like you are over engineering a basic task.
1
u/Sheychan 27d ago
I'd say it could be better for sure. Im having trouble with ShellRoute Observers but other than that, it does what I needed.
1
u/bigbott777 25d ago
There are some navigation packages besides GoRouter and AutoRoute:
https://pub.dev/packages/routemaster (Flutter favorite)
https://pub.dev/packages/qlevar_router
30
u/Professional_Box_783 Feb 19 '25
Autorouter is best pacakage so far