简体   繁体   English

如何根据Flutter中下拉菜单中选中的item更改Form

[英]How to change the Form according to the item selected in the drop Down menu in Flutter

I have created I method which is showing a dialog and I called it with timer.run() method in order to show the dialog at the start of the screen automatically in which i have created a form (the code snippet is attached in the photos) and the form contains drop-down menu with two items(check and bank) now i want to make the UI as dynamic whenever the user selects the Bank option in the drop-down menu a new drop-down menu is displayed to him otherwise an empty container will be displayed to him.我创建了显示对话框的方法,并使用timer.run()方法调用它,以便在屏幕开头自动显示对话框,我在其中创建了一个表单(代码片段附在照片中) 并且表单包含带有两个项目(支票和银行)的下拉菜单将向他显示一个空容器。

Solutions I tried我尝试过的解决方案

  1. created i variable which holds true if the item selected is bank otherwise false and used it as a condition to either show the 2nd drop-down or not.创建 i 变量,如果所选项目是银行,则该变量为真,否则为假,并将其用作显示第二个下拉列表或不显示的条件。
  2. Make the variable global but it also didn't worked.使变量成为全局变量,但它也没有用。
  3. created a function which i called with the variable to return either drop-down or empty container but it also didn't worked.创建了一个 function,我用变量调用它以返回下拉列表或空容器,但它也没有用。
  4. Created the bank selected variable in other class and access it with provider package but it also didn't worked for me.在其他 class 中创建了 bank selected 变量,并通过提供者 package 访问它,但它对我也没有用。

The source code is also available at Github-Repo源代码也可以在Github-Repo上找到

_showDialog 显示对话框的方法 在 initState 方法中调用 _showDialog 方法以便在屏幕开始处显示对话框

Thanks all someone at linkedin helped me with the solution.感谢 linkedin 的所有人帮助我解决了这个问题。 which is We have to wrap the AlertDialog with StatefulBuilder and have to call setState when option is selected then it will work.这是我们必须用 StatefulBuilder 包装 AlertDialog 并且必须在选择选项时调用 setState 然后它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM