When using GoRouter for declarative navigation, you'll often have to choose between:
- GOING to a route
- PUSHING a route
What is the difference between the two?
A thread. π§΅
To start off, let's consider a simple route hierarchy made of one top route with two sub-routes.
Let's also define 3 pages for our routes:
Now, suppose that we're in the HomeScreen.
From here, we can either call `context.go('/detail')` or `context.push('/detail')`, and end up with the same result.
That is, in both cases we'll have two routes in the navigation stack (home β detail).
From the detail page, we can now call `context.go('/modal')` or `context.push('/modal')`.
This time the result is different:
- If we use "go", we end up with the modal page on top of the *home* page
- If we use "push", we end up with the modal page on top of the *detail* page
That's because "go" jumps to the target route (/modal) by *discarding* the previous route (/detail), since /modal is *not* a sub-route of /detail.
Meanwhile, "push" always adds the target route on top of the existing one, preserving the navigation stack.
This means that once we dismiss the modal page, we navigate back to:
- the home page, if we used "go"
- the detail page, if we used "push"
Here's a short video showing this behavior:
The bottom line?
Think of `go` as a way to *jump* to a new route. This will modify the underlying navigation stack if the new route is not a sub-route of the old one.
On the other hand, `push` will always push the destination route on top of the existing navigation stack.
For more info about GoRouter, make sure to check the official documentation (it's excellent):
If your users speak another language, youβll need to localize your Flutter app πΊ
Hereβs how to setup Flutter app localizations in just 5 minutes, using code generation.
Also covered: template vs non-template files and synthetic vs non-synthetic package. π
π§΅
1οΈβ£ As a first step, we need to add the required packages to the pubspec.yaml file.
2οΈβ£ Create l10n.yaml at the root
βοΈ arb-dir is the input folder where Flutter will look for the localized strings
βοΈ output-dir is where the localizations classes will be generated
βοΈ template-arb-file is the main template that contains a description for each localized message
What's the difference between errors and exceptions in Flutter?
β Errors are programmer mistakes. They are fatal and we should not try to recover from them
β Exceptions are failure conditions that are out of our control. We should handle them and recover gracefully
Thread π§΅
Errors are fatal and when they happen the program *cannot* recover normally.
β we want to discover (and fix) them as early as possible in the development process
β we should track them in production using a crash reporting solution, so that we can measure impact and severity