[英]How to go back to the previous page in flutter upon button press?
Upon pressing the button the below command is executed successfully.按下按钮后,以下命令将成功执行。
Navigator.push(context, MaterialPageRoute(builder:(context)=>NewForm(stateCheck: widget.state1,)));
But I want this to happen on a certain boolean condition, if the condition is false then the above should be executed else upon pressing the button the navigation should be done to the previous screen.但我希望这发生在某个 boolean 条件下,如果条件为假,则应在按下按钮时执行上述操作,否则导航应完成到上一个屏幕。
if (a == b){
Navigator.push(context, MaterialPageRoute(builder:(context)=>NewForm(stateCheck: widget.state1,)));
} else {
//what command should be written here to move to back to previous screen
}
In clear summary, there are 3 screens, S1, S2 and S3 respectively.简而言之,有3个屏幕,分别是S1、S2和S3。 Current Screen is S2,upon pressing the button if condition is false user should move to screen S3 and if condition is true user should move to screen S1, How should I achieve it?当前屏幕是 S2,如果条件为假,则按下按钮后,用户应移至屏幕 S3,如果条件为真,用户应移至屏幕 S1,我应该如何实现?
If screen S1 is different from the flow like if your flow is S1->S2->S3, then to go back to S1 you can do Navigator.pop(context)
this will navigate you to S1 back to S2.如果屏幕 S1 与流程不同,例如您的流程是 S1->S2->S3,然后到 go 回到 S1,您可以执行Navigator.pop(context)
这会将您导航到 S1 回到 S2。
If your flow is different means you are coming on S2 from other than S1 say S3 but want to go to S1 then use Navigator.push()
as you did earlier.如果您的流程不同,则意味着您从 S1 以外的 S2 进入 S3,但想从 go 到 S1,然后像之前一样使用Navigator.push()
。
I think this should solve your issue..我认为这应该可以解决您的问题..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.