0

I am having a multiple FormBuilder dropdown in my flutter app. all of them are dependent dropdown. i want to implement something like this:

  1. the first of the main parent dropdown value should be auto fill and hence all other are filled or selected depending on the parents selection.
  2. I can see the text filled in all the dropdown but as it is the dependent it is disabled for first dropdown to be clicked once.

How to fix this issue?

in the below screenshot we can see that the data is filled or been selected in every dropdown but second dropdown is still been disabled. it only gets enabled after clicking or selecting the value in first dropdown. enter image description here

Here is my code for first dropdown

                padding: const EdgeInsets.all(12.0),
                child: FormBuilderDropdown(
                  name: 'City',
                  decoration: InputDecoration(
                    labelText: 'City',
                  ),
                  allowClear: true,
                
                  hint: Text(widget.callLocationModel.CityName),
                  initialValue: citySelected,

                  validator: FormBuilderValidators.compose(
                      [FormBuilderValidators.required(context)]),
                  items: cityList
                      .map((citySelected) => DropdownMenuItem(
                          value: cityChoosen,
                          child:new Text('$citySelected'),
                          ))
                      .toList(),
                  onChanged: (String value){
                      setState(() {
                        citySelected= value;
//this fuction calls my second dropdown depending on first dropdown value selection
                        fetchSite(citySelected);
                      });
                  },
                ),
              ),

1 Answer 1

0

I assume all this layout is done in a stageful widget, which has a variable in it’s state for each selected value (when it’s selected). You may override initState member function and set the initial values there, so when the widget is built for the first time it will have those values preselected.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.