void main() {
runApp(MaterialApp(
title: '导航路由示例',
home: FirstPage(),
));
}
class FirstPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('第一个页面'),
),
body: Center(
child: RaisedButton(
child: Text('进入第二个页面'),
onPressed: () {
Navigator.push(context,MaterialPageRoute(builder: (context) => SecondPage()));
},
),
)
);
}
}
class SecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('第二个页面'),
),
body: Center(
child: RaisedButton(
child: Text('返回第一个页面'),
onPressed: () {
Navigator.pop(context);
},
),
),
);
}
}
Flutter笔记62:Route最基本的使用
Fluter路由Route导航Navigator最基本的使用:push进入某个页面(入栈)、pop关闭本页面(出栈):
