Saturday 26 January 2019

value == null || items.where((DropdownMenuItem item) => item.value == value).length == 1

I/flutter (23889): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
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,
);
}

No comments:

Post a Comment