I/flutter (23889): The following assertion was thrown building DropdownButtonFormField<dynamic>(dirty, state:
I/flutter (23889): _DropdownButtonFormFieldState<dynamic>#94f46):
I/flutter (23889): 'package:flutter/src/material/dropdown.dart': Failed assertion: line 514 pos 15: 'items == null ||
I/flutter (23889): value == null || items.where((DropdownMenuItem<T> item) => item.value == value).length == 1': is not
I/flutter (23889): true.
........................'
use init state to initialize value part in
buildDropdownButtonFormField
void initState() {
String x = controller.text; //on update initial value
x = x.trim();
if (x != "" && x != null) {
selectBoxvalue = x;
}
super.initState();
}
buildDropdownButtonFormField(BuildContext context) {
return DropdownButtonFormField(
items: dropDownList.toList(),
decoration: InputDecoration(
labelText: Translations.of(context).text(label),
),
onChanged: (value) {
setState(() {
selectBoxvalue = value;
});
if (controller != null) {
controller.text = value;
}
if (onChangeSelectMap != null) {
onChangeSelectMap(value);
}
},
value: selectBoxvalue ?? null,
);
}