DEV Community

Prince Srivastava
Prince Srivastava

Posted on

Managing Named Routes in Flutter with Extensions

We can use Named Routing with flutter in an efficient way with extension methods.
Alt Text

With these extension methods we have less chances to committing any error or typo.
Alt Text
And in MyApp widget use it accordingly.

With Navigator.pushNamed(); we can use it in the following way --
Alt Text

Top comments (5)

Collapse
 
kush3107 profile image
Kushagra Saxena

Great explanation.

Collapse
 
abdulbasitsaid profile image
Abdulbasit

what if you need to pass perimeters.

Collapse
 
pr1 profile image
Prince Srivastava

You can use arguments for that.

Collapse
 
pr1 profile image
Prince Srivastava

Navigator.pushNamed(context, RouteName, argument: data);

Retrive it by - ModalRoute.of(context).settings.arguments

Collapse
 
abdulbasitsaid profile image
Abdulbasit

what if you need to pass parameters