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(),
},
);
navigator push named
var exampleArgument = 'example string';
Navigator.pushNamed(
context,
ImagesScreen.routeName,
arguments: {'exampleArgument': exampleArgument},
);
and extract the arguments as follows:
@override
Widget build(BuildContext context) {
final arguments = ModalRoute.of(context).settings.arguments as Map;
if (arguments != null) print(arguments['exampleArgument']);
return Scaffold(...);
}
|