一、当前页A 跳转 B (无参)
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) => (PageB())),
);
二、当前页A 跳转 B (有参)
A:
Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) => (PageB('参数'))),
);
B:(接收参数)
class PageB extends StatelessWidget {
String str;
PageB(this.str);
}
三、当前页A 跳转 B (有参),并在A接收B返回的数据
A:
Navigator.push<String>(context,
MaterialPageRoute(builder: (BuildContext context) {
return PageB('参数');
})).then((String res) {
print('B返回的内容:'+res);
});
B:(返回A并携带参数)
Navigator.of(context).pop('1');
四、A-B-C-D,从D直接返回A
C:(跳转并销毁之前所有路由)
Navigator.pushAndRemoveUntil(context,
new MaterialPageRoute(
builder: (BuildContext context) {
return new PageD();
},
), (route) => route == null);
五、A-B-C ,跳转下一页并销毁当前页
B到C之后,从C返回直接到A
Navigator.pushReplacement(context, new MaterialPageRoute(
builder: (BuildContext context) {
return new PageD();
},);
六、回到首页(栈顶)
Navigator.popUntil(context, ModalRoute.withName('/'));