页面跳转
- 无参跳转
SecondController:Navigator.push(context, MaterialPageRoute( builder: (context) => SecondController(), ), );
class SecondController extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('第二页'), centerTitle: true, ), body: Container(), ); } }
- 带参数跳转
SecondController接收参数:Navigator.push(context, MaterialPageRoute( builder: (context) => SecondController(title: '第二页',), ), );
class SecondController extends StatelessWidget { final String title; SecondController({Key key, this.title}): super(key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(title), centerTitle: true, ),