In Flutter, Navigation refers to moving between different screens (called routes) in your app. Routing is the technique used to define and manage those transitions.
// Navigate to a new screen
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondScreen()),
);
// Go back to previous screen
Navigator.pop(context);
Navigator.push() to move forward and Navigator.pop() to go back.
Named routes help manage navigation in larger apps by giving each route a name.
void main() {
runApp(MaterialApp(
initialRoute: '/',
routes: {
'/': (context) => HomeScreen(),
'/about': (context) => AboutScreen(),
},
));
}
// Navigate using name
Navigator.pushNamed(context, '/about');
Imagine an app as a house with many rooms. Each room is a screen. Navigation is like walking from one room to another, and the Navigator keeps track of where you've been so you can go back if needed.
For more, check Flutter's official Navigation guide.