I have many screens, and I'm using the Navigator
. I'd like to use "named routes", but I also need to pass non-string (such as images) to my next route.
I can't use pushNamed()
because I can't pass non-string data to it.
How can I use a named route + send non-string data?
The solution is to define a named route, and use the named route for navigation. To work with named routes, use the Navigator.
EDIT:
It is now possible to pass complex arguments to Navigator.pushNamed
:
String id; Navigator.pushNamed(context, '/users', arguments: id);
It can then be used within onGenerateRoute
to customize route building with these arguments:
MaterialApp( title: 'Flutter Hooks Gallery', onGenerateRoute: (settings) { final arguments = settings.arguments; switch (settings.name) { case '/users': if (arguments is String) { // the details page for one specific user return UserDetails(arguments); } else { // a route showing the list of all users return UserList(); } default: return null; } }, );
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