简体   繁体   English

按下按钮后如何 go 返回 flutter 中的上一页?

[英]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.

相关问题 如何使设备返回按钮到 go 到 flutter 中的上一页 webview - How to make device back button to go to the previous page in flutter webview go如何在Flutter返回刷新上一页? - How to go back and refresh the previous page in Flutter? Go 返回上一页 flutter - Go back to previous page in flutter 单击手机后退按钮时如何在前一页中颤动 - How to go previous page in flutter while clicking mobile phone back button 如何在单击按钮时使用 flutter_webview 返回上一页? - How can I go back to the previous page with flutter_webview on button click? 在 Flutter 中按下设备后退按钮时如何转到上一个选项卡? - How to go to the previous Tab when the Device Back Button is pressed in Flutter? 我如何阻止用户在颤动中返回上一页 - How I can block user to go back to the previous page in flutter 刷新页面浏览量颤动中的屏幕时如何返回上一页 - how to go back to previous page when refresh the screen in pageview flutter 如何 go 在 flutter 中使用 page_transition 在一次背压中返回多个页面 - How to go back multiple pages in one back press with page_transition in flutter 如何使用设备后退按钮导航到上一页 - Flutter - How to navigate to previous page using device back button - Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM