Home > OS >  How to change the Form according to the item selected in the drop Down menu in Flutter
How to change the Form according to the item selected in the drop Down menu in Flutter

Time:06-14

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.

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.
  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.
  4. Created the bank selected variable in other class and access it with provider package but it also didn't worked for me.

The source code is also available at _showDialog method which is displaying dialog calling _showDialog method in initState method in order to show the dialog at the start of the screen

CodePudding user response:

Thanks all someone at linkedin helped me with the solution. which is We have to wrap the AlertDialog with StatefulBuilder and have to call setState when option is selected then it will work.

  • Related