title: How to force flutter to rebuild a specific widget when setState is called
body: <p>I have a <code>stateful widget</code> class. It has a listView in its build method. Inside the list view I have two <code>dropDownButtonFormField</code>. Initially, only the first drop down is shown. After a value is selected in to, the second drop down is drawn by calling the <code>set state</code>. The second drop down button is dependent on the first button's choice.</p>
  
  <p>Now the code works fine. After selecting the value in the first drop down button, the second drop down button appears with options corresponding to the first's selected value. But error occurs when a an option from the second button is selected and first button's option is changed. </p>
  
  <p>How do I force flutter to redraw the second dropdown every time the first drop down's selected option is changed?</p>
  
  <p>Here is the app running and crashing:</p>
  
  <p><a href="https://i.stack.imgur.com/ccBD5.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ccBD5.gif" alt="app giving error"></a></p>
  
  <p>Code:</p>
  
  <pre><code>//called inside the list view childrens list
  Widget showLocationDropDown() {
      return Padding(
        padding: const EdgeInsets.fromLTRB(0.0, 20.0, 0.0, 0.0),
        child: Container(
          child: Column(
            children: &lt;Widget&gt;[
              _getProvinceDropDown(),
              _selectedProvince == null ? Container(): _getCityDropDown(),
            ],
          ),
        ),
      );
    }
  
   Widget _getCityDropDown() {
      return Column(
        children: &lt;Widget&gt;[
          Container(
            height: 20,
          ),
          Row(
            children: &lt;Widget&gt;[
              Icon(Icons.location_city, color: Colors.grey),
              Container(
                width: 17.0,
              ),
              Expanded(
                child: ButtonTheme(
                  alignedDropdown: true,
                  child: DropdownButtonFormField(
                    decoration: InputDecoration(
                        enabledBorder: OutlineInputBorder(
                            borderRadius: BorderRadius.circular(25.0),
                            borderSide: BorderSide(color: Colors.grey))),
                    hint: Text('Please choose your city'),
                    value: _selectedCity,
                    onChanged: (newValue) {
                      setState(() {
                        _selectedCity = newValue;
                      });
                    },
                    items: _getCities().map((location) {
                      return DropdownMenuItem(
                        child: Text(location),
                        value: location,
                      );
                    }).toList(),
                  ),
                ),
              ),
            ],
          ),
        ],
      );
    }
  
    List&lt;String&gt; _getCities() {
      switch (_selectedProvince) {
        case ("Sindh"):
          return _sindhCities;
  
        case ("Punjab"):
          return _punjabCities;
  
        case ("Balouchistan"):
          return _balouchCities;
  
        case ("KPK"):
          return _kpkCities;
      }
      List&lt;String&gt; deflt = ['Please Select Province'];
      return deflt;
    }
  
    Widget _getProvinceDropDown() {
      return Row(
        children: &lt;Widget&gt;[
          Icon(Icons.map, color: Colors.grey),
          Container(
            width: 17.0,
          ),
          Expanded(
            child: ButtonTheme(
              alignedDropdown: true,
              child: DropdownButtonFormField(
                decoration: InputDecoration(
                  enabledBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(25.0),
                    borderSide: BorderSide(color: Colors.grey),
                  ),
                ),
                hint: Text('Please choose your province'),
                value: _selectedProvince,
                onChanged: (newValue) {
                  setState(() {
                    _selectedProvince = newValue;
                    _selectedCity = null;
                    stateChange = !stateChange;
                  });
                },
                items: _province.map((province) {
                  return DropdownMenuItem(
                    child: Text(province),
                    value: province,
                  );
                }).toList(),
              ),
            ),
          ),
        ],
      );
    }
  
  </code></pre>