Reputation: 535
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!
Upvotes: 9
Views: 1120
Reputation: 277527
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.
Upvotes: 12