Navigation from one page to other is vital part in mobile app development.
Flutter comes with very easy solutions for navigation using 🥰Navigator🥰 class.
In this post I am going to cover two types of navigation in flutter.
1) Simple navigation
2) Named navigation
Our scenario is to move to the second page on button pressed, we were taking two pages
1) Home page
2) Second page
also we are passing a string to second page.
Simple navigation can be achieved by using Navigator push method
the syntax for Navigator push is
'Navigator.push(context, MaterialPageRoute(builder: (context) => Widget()));'
Seems simple isnt it, See below for code snippet.
I would say this is the best way to handle navigation, you will find the answer soooon 😉
Named navigation is using routing concept, now you get it why it is the best way ahhh 😇
All the navigation routes are isolated/dedicated in one place, so we don't need to worry about instantiating class in our dart code.
lets jump into the code.
Flutter Material app comes with function callback for generating the App routes
We can define our routes in a function and set it to onGenerateRoute, so that flutter knows where to go on navigation.
Syntax for named routing using navigator:
Navigator.of(context).pushNamed('/route', arguments: args);
even simple isn't it??
See below code snippet
for full sample please find in the Github repo link
Happy fluterring 😇😇!!