i'm reviewing the flutter.dev tutorials. I'm a bit confused by 2 of their articles.
1) Send data to a new screen https://flutter.dev/docs/cookbook/navigation/passing-data
2) Pass arguments to a named route https://flutter.dev/docs/cookbook/navigation/navigate-with-arguments
To me, they more or less both accomplish the same thing but in different ways. It seems #1 passes the data using Navigator's "arguments" parameter and then pulls it out in the target widget via ModalRoute.of(context).settings.arguments. It seems #2 uses the target widget's constructor to receive the data. Am I missing something? When would I use one vs the other?
Thanks!
Flutter provides two types of APIs for navigation: imperative and declarative.
In flutter, the pages or screens are called Routes. In android, these pages/screens are referred to as Activity and in iOS, it is referred to as ViewController. But, in a flutter, routes are referred to as Widgets. In Flutter, a Page / Screen is called a Route.
There are two main differences:
Route
subclass. Using push
, it's the widget that calls Navigator.push
whereas using pushNamed
, it's MaterialApp
/CupertinoApp
or onGenerateRoute
.This has an impact on features such as transitions between routes, separation of concern, or deep links.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With