flutter on generate route code example
Example 1: flutter not navigating to a new screen
Wrap the new screen with a Scaffold widget
//navigation page
return GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DestinationScreen()),
);
}
// new screen page
class _DestinationScreenState extends State {
@override
Widget build(BuildContext context) {
return Scaffold();
}
}
Example 2: 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(),
},
);