multiselect_formfield
multiselect_formfield copied to clipboard
How can i clear/remove old value when change to new multiselect formfield
Here my follow. Thanks



<--- because new multiselect formfield dont have selected item.
@cetorres @DavidCorrado @SurajLad
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
- Set datasource and an initial value
- Change the datasource to one that does not contain any element from the initial value
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 :(
https://github.com/cetorres/multiselect_formfield/compare/master...hampsterx:issue_32_clear_old_value_bug
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..