multiselect_formfield icon indicating copy to clipboard operation
multiselect_formfield copied to clipboard

How can i clear/remove old value when change to new multiselect formfield

Open Thaimay opened this issue 5 years ago • 3 comments

Here my follow. Thanks

  1. image
  2. image
  3. image
  4. image <--- because new multiselect formfield dont have selected item.
  5. image

@cetorres @DavidCorrado @SurajLad

Thaimay avatar Nov 20 '20 04:11 Thaimay

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

  1. Set datasource and an initial value
  2. 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.

ayinloya avatar Nov 26 '20 21:11 ayinloya

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?

rsree1210 avatar May 30 '21 23:05 rsree1210

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..

hampsterx avatar May 30 '21 23:05 hampsterx