- 根目录
push到页面一
Navigator.of(context, rootNavigator: true).push(CupertinoPageRoute(
builder: (BuildContext context) {
return new Page1();
},
settings: RouteSettings(name: "/page1"),
));
其中of中rootNavigator为true,route中使用settings来设置页面一的route的name,便于以后pop到当前页面。
- 页面一
push到页面二
Navigator.of(context).push(CupertinoPageRoute(
builder: (BuildContext context) {
return new Page2();
},
settings: RouteSettings(name: "/page2"),
));
- 页面二
push到页面三
Navigator.of(context).push(CupertinoPageRoute(
builder: (BuildContext context) {
return new Page3();
},
settings: RouteSettings(name: "/page3"),
));
- 页面三
pop到根目录
Navigator.of(context).popUntil(ModalRoute.withName('/'));
或
Navigator.of(context).popUntil((r) => r.settings.isInitialRoute);
- 页面三
pop到上一个页面
Navigator.of(context).pop();
- 页面三
pop到页面二
Navigator.of(context).popUntil(ModalRoute.withName('/page2'));
- 页面三
pop到页面一
Navigator.of(context).popUntil(ModalRoute.withName('/page1'));










