DEV Community

Prince Srivastava
Prince Srivastava

Posted on

6 3

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

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay