custom-dropdown icon indicating copy to clipboard operation
custom-dropdown copied to clipboard

Runtime error when passing immutable list -> Unsupported operation: Cannot remove / add from an unmodifiable list

Open mqhamdam opened this issue 11 months ago • 1 comments

Error occurs using multiSelect factory

Flexible(
  child: CustomDropdown.multiSelectSearch(
    key: const Key("PickScanItems-ItemSerials"),
    items: itemSerialsList.isEmpty ? [kEmptyList] : itemSerialsList,
    onListChanged: _onItemSerialsChange,
    hintText: "Select Item Serials",
    initialItems: itemSerials.isEmpty ? null : itemSerials,
  ),
),

itemSerials and itemSerialsList are unmodifiable list (using freezed for immutability)

is it possible to refactor remove/add events in immutable way? or is it possible to give developer to handle events by callbacks?

mqhamdam avatar Mar 06 '24 07:03 mqhamdam

if anyone else have same problem, you could use below example :

Flexible(
  child: CustomDropdown.multiSelectSearch(
    key: const Key("PickScanItems-ItemSerials"),
    items: itemSerialsList.isEmpty
        ? [kEmptyList]
        : List.of(itemSerialsList),
    onListChanged: _onItemSerialsChange,
    hintText: "Select Item Serials",
    initialItems: itemSerials.isEmpty ? null : List.of(itemSerials),
  ),
),

Basically I'm creating new modifiable list from unmodifiable list.

I keep open the issue cuz i think it would be good to have options for developers to choose and make CustomSearch widget more flexible in use.

mqhamdam avatar Mar 06 '24 08:03 mqhamdam