1

I m new to flutter, need help to set the value of the DropdownButton programmatically. The value is from textfield. Once i click it, it will set the value at the dropdownbutton automatically.

Widget _districtListContainer() {
    return Container(
        width: 360.0,
        child: new InputDecorator(
          decoration: InputDecoration(
              suffixIcon: new Icon(
                Icons.search,
                color: Colors.blue[700],
              ),
              labelText: 'Select District',
              labelStyle: TextStyle(fontSize: 12.0)),
          isEmpty: _selectedDistrict == null,
          child: new DropdownButtonHideUnderline(
            child: new DropdownButton<District>(
             
              value: _selectedDistrict,
              isDense: true,
              isExpanded: false,
              onChanged: (District newValue) {
                setState(() {
                  _selectedDistrict = newValue;
             
                });
              },
              items: _listDistrict?.map((District value) {
                    return new DropdownMenuItem<District>(
                      value: value,
                      child: new Text(
                        value.district != null ? value.district : '',
                        style: new TextStyle(fontSize: 11.0),
                      ),
                    );
                  })?.toList() ??
                  [],
            ),
          ),
        ),
        margin: EdgeInsets.only(bottom: 10.0));
  }

thanks

Felipe Vergara
  • 849
  • 7
  • 12
LKC
  • 51
  • 4

1 Answers1

0

First Of All, Add the data into the list[] From the TextFormfield then retrieve the list into DropDownButton item.

Also, Make Sure, DropDown Button List Display Textformfield data insert activity could not be able to update simultaneously.