嵌套导航器pushNamedAndRemoveUntil谓词路由为null

时间:2019-10-26 22:39:22

标签: flutter dart flutter-navigation

我正在尝试pushNamedAndRemoveUntil,但我注意到我的谓词不断返回null作为路由。

我的代码:

Navigator.pushNamedAndRemoveUntil(
  context, 'search/studyPage',
  (Route<dynamic> route) {
    print(route);
    return false; // im returning false to illustrate that all the routes being "popped" are all returning null
    }, 
  arguments: StudyPageArgs(widget.study)
);

此打印:

MaterialPageRoute<dynamic>(RouteSettings("null", null), 
animation: AnimationController#117d7(⏭ 1.000; paused; 
for MaterialPageRoute<dynamic>(null)))
MaterialPageRoute<dynamic>(RouteSettings("null", null), 
animation: AnimationController#117d7(⏭ 1.000; paused; 
for MaterialPageRoute<dynamic>(null)))
MaterialPageRoute<dynamic>(RouteSettings("null", null), 
animation: AnimationController#117d7(⏭ 1.000; paused; 
for MaterialPageRoute<dynamic>(null)))
MaterialPageRoute<dynamic>(RouteSettings("null", null), 
animation: AnimationController#117d7(⏭ 1.000; paused; 
for MaterialPageRoute<dynamic>(null)))

当我这样做时,我可以按原路行驶,但是从那里弹出会给我一个空白屏幕。这是因为谓词不断返回null,因此所有先前的路由都从树中删除。知道发生了什么事吗?

请记住,我使用的是嵌套导航器设置,与此处的其他问题相同:(.popUntil with nested navigators

谢谢

2 个答案:

答案 0 :(得分:0)

我想出了一种拙劣而糟糕的方法。它仍然可以工作

Navigator.pushNamedAndRemoveUntil(
  context, 'search/studyPage',
  (Route<dynamic> route) {
setState(() {
  _popper = _popper + 1;
});
if (_popper == 4) {
  return true;
} else {
  return false;
}
}, arguments: StudyPageArgs(widget.study));

答案 1 :(得分:0)

settings参数是必需的:

MaterialPageRoute(builder: builder, settings:  settings