38
loading...
This website collects cookies to deliver better user experience
void main() async {
runApp(
MaterialApp(debugShowCheckedModeBanner: false,
initialRoute: '/',
routes: {
'/': (context) => RouteOne(),
'/detail': (context) => RouteTwo(),
}),
);
}
/
./
which will render a widget called: RouteOne
/detail
, which renders a widget called: RouterTwo
class RouteOne extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Screen one ☝️'),
),
body: Center(
child: ElevatedButton(
// Within the `FirstScreen` widget
onPressed: () {
// Navigate to the second screen using a named route.
Navigator.pushNamed(context, '/detail');
},
child: Text('Open detail'),
),
),
);
}
}
/detail
.class RouteTwo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Screen two ✌️'),
),
body: Center(
child: ElevatedButton(
// Within the `FirstScreen` widget
onPressed: () {
// Navigate to the second screen using a named route.
Navigator.pop(context);
},
child: Text('Go back'),
),
),
);
}
}
pop
function, which will remove the last pushed route from the stack.