Flutter 导航路线未删除或弹出
目前,我正在我的应用程序上做一个安全设置页面。现在,我遇到的问题是当我返回或按下后退按钮时。这些页面甚至在弹出窗口中仍在导航 我使用我的代码,我将使用它进入第一个流Flutter 导航路线未删除或弹出,flutter,flutter-navigation,Flutter,Flutter Navigation,目前,我正在我的应用程序上做一个安全设置页面。现在,我遇到的问题是当我返回或按下后退按钮时。这些页面甚至在弹出窗口中仍在导航 我使用我的代码,我将使用它进入第一个流 Navigator.push( context, MaterialPageRoute(builder: (context) => otp_mPin()) 现在在第二个或反向流中,我使用了这个 在OTP页面上,我使用了pop和push Navigator.of(context).pop();
Navigator.push(
context,
MaterialPageRoute(builder: (context) => otp_mPin())
现在在第二个或反向流中,我使用了这个
在OTP页面上,我使用了pop和push
Navigator.of(context).pop();
Navigator.push(
context,
MaterialPageRoute(builder: (context) => mPin())
这是我得到的流量
屏幕1设置页面
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => ProtectPhone()));
},
屏幕2带密码的页面
成功密码导航
onPressed: (){
Navigator.pop(context);
Navigator.push(context, MaterialPageRoute(builder: (context) => selectScreenLock()));
},
后退按钮/willPop
Navigator.pop(context);
屏幕3选择
选择或单击将重定向到OtpMpin页面的MPin
Navigator.push(
context,
MaterialPageRoute(builder: (context) => OtpMpin())
);
Back或willpop命令
Navigator.of(context).pop();
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ProtectPhone())
);
Navigator.of(context).pop();
Navigator.push(
context,
MaterialPageRoute(builder: (context) => selectScreenLock())
Secreen 4 OTP
OTP输入成功
Navigator.pop(context);
Navigator.push(context, MaterialPageRoute(builder: (context) => setMPin()));
屏幕5 MPIN
Back或Willpop命令
Navigator.of(context).pop();
Navigator.push(
context,
MaterialPageRoute(builder: (context) => ProtectPhone())
);
Navigator.of(context).pop();
Navigator.push(
context,
MaterialPageRoute(builder: (context) => selectScreenLock())
第一流
1>2>3>4>5
二次流或回流
5>3>2>4>2>1在第3页到第4页中使用pushReplacement方法,以便在从第3页导航到第4页时,从堆栈中删除第3页并将其推到第4页。所以,若用户在第四页按下后退按钮,那个么用户将得到第二页
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) {
return NewPage();
}));
在推送新页面之前,为什么要使用pop?你能添加你所有的5个文件导航代码吗?@MSARKrish我在推送时理解的是,它正在正确地堆叠页面。我希望从堆栈中删除并替换这些页面。因为第3-5页是安全页面,不进入第2页和第4页就无法访问。等等,我将在每页上放置导航代码。您可以使用Navigator.of(context).pushReplacement()函数。谢谢。我将尝试此操作。是的,但在第5页,当我按back时,我重定向到了4thNavigator.pushReplacement(context,MaterialPageRoute(builder:(context)=>setMPin());在第4页,我应该删除navigator.pop吗?在第3页中使用pushReplacement,因为你说第3页和第5页是重要的用户,请在第2页和第4页中转到该页,所以仅在第3页中使用此选项。如果您有第6页,则在第5页中使用此方法。