routes flutter code example
Example 1: flutter navigate to new screen
// Within the `FirstRoute` widget
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
}
Example 2: named routes flutter
MaterialApp(
routes: {
'/':(context)=>HomePage(),
'/meals':(context)=>MealsPage(),
'/orders':(context)=>Orders(),
},
);
Example 3: routes in flutter
routes in flutter
Example 4: routes in flutter
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
Example 5: material app routes
///////////////////////////////////////
// Setting up routes on material app //
///////////////////////////////////////
MaterialApp(
// Start the app with the "/" named route. In this case, the app starts
// on the FirstScreen widget.
initialRoute: '/',
routes: {
// When navigating to the "/" route, build the FirstScreen widget.
'/': (context) => FirstScreen(),
// When navigating to the "/second" route, build the SecondScreen widget.
'/second': (context) => SecondScreen(),
},
);