Open Thaimay opened 3 years ago
I'm also getting this issue, Any solution yet?
The error occurs when the selected values are not present in the new datasource
How to reproduce
I guess the error comes from here
state.value.forEach((item) {
var existingItem = dataSource.singleWhere((itm) => itm[valueField] == item, orElse: () => null); // <-- this returns null when the item is not in the datasource
selectedOptions.add(Chip(
labelStyle: chipLabelStyle,
backgroundColor: chipBackGroundColor,
label: Text(
existingItem[textField], // <-- this calls [] on a null object
overflow: TextOverflow.ellipsis,
// style: TextStyle(color: Colors.red),
),
));
});
Selected elements can be ignored
state.value.forEach((item) {
var existingItem = dataSource.singleWhere((itm) => itm[valueField] == item, orElse: () => null);
// there could be a null check here to ignore value not present in new datasource
if(existingItem != null){
selectedOptions.add(Chip(
labelStyle: chipLabelStyle,
backgroundColor: chipBackGroundColor,
label: Text(
existingItem[textField],
overflow: TextOverflow.ellipsis,
// style: TextStyle(color: Colors.red),
),
));
}
});
If it's ok I can make a pull request.
I am also facing the same issue. Any update on when the package will fix this issue? Or can anyone suggest any alternative solution to clear the field?
very temp fix, use my fork :(
this add a key and also avoids null bug here.
multiselect_formfield:
# https://github.com/cetorres/multiselect_formfield/issues/32
git:
url: git://github.com/hampsterx/multiselect_formfield.git
ref: issue_32_clear_old_value_bug
Didn't submit PR as wasn't sure if this is right fix or not. Works ok tho..
Here my follow. Thanks
@cetorres @DavidCorrado @SurajLad