I have been trying to make a Dynamic DropDown List (The user can create different dropdowns and fetch all of then in a list). I have been able to fetch the data and display it in the dropdown menu, but haven't been able to updating value of the dropdown dynamically.
These codes are from the ListView.builder() :
String _currentData = "";
for (int i = 0; i < SignUpField[index]["DropDownOptions"].length; i++) {
_currentData = SignUpField[index]["DropDownOptions"].toList().first;
}
Container(
width: (size.width * 1) - 60,
height: 60,
padding: EdgeInsets.only(left: 20, right: 20, top: 10, bottom: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
border: Border.all(
width: 0.3,
color: Color(0xffCFCFCF),
),
),
child: FormField<String>(
builder: (FormFieldState<String> state) {
return DropdownButtonHideUnderline(
child: DropdownButton(
isDense: true,
isExpanded: false,
value: _currentData,
items: _dropDownItem(SignUpField[index]["DropDownOptions"]),
onChanged: (value) {
setState(() {
_currentData = value.toString();
state.didChange(value.toString());
print(_currentData);
});
},
hint: Text('Select Option'),
),
);
},
),
),
List<DropdownMenuItem<String>> _dropDownItem(List list) {
late List<String> ddl = [];
for(var menu in list) {
ddl.add(menu);
}
return ddl.map((value) => DropdownMenuItem(
value: value,
child: Text(value),
)).toList();
}
Thank You