Good time
I have two dropdowns on one page
The first is a list of cars and the second is the model of the cars.
Now, when I select Mercedes in the first drop-down menu, for example, I want the exact model name of the car brand to appear in the second drop-down menu.
For example, I choose Mercedes and in the next drop down, the list of Mercedes cars will be shown to me.
How can I handle it?
I am a newbie. And maybe it is better to give a more comprehensive explanation
2
Answers
There are several ways to handle this.
You can track the selected field, by adding it as a variable on your application, and everytime you select a new value, that variable is changed ex:
You can either have a variable (flag) in the builder that changes what is presented depending on its value,
Ex: when a new value is selected on the first dropdown, you change the value of a variable, and the second dropdown loads a list based on that value.
Ex:
or
Create a state change where you load different values to the list depending on the selected value, with a stateChange of a StatefulWidget.
Use Map to store the Manufacturer. For e.g. :
And also store list of cars using a map like this:
Then create a key variable which will stored key of selected brand.
Then U can now choose the cars u desire using the key u chose for brand in dropdown.