set method Null safety
Adds or removes a barcode within a product list (depending on include
)
Returns true if there was a change in the list.
Implementation
bool set(
final ProductList productList,
final String barcode,
final bool include,
) {
final _BarcodeList? list = _get(productList);
final List<String> barcodes;
if (list == null) {
barcodes = <String>[];
} else {
barcodes = _getSafeBarcodeListCopy(list.barcodes);
}
if (barcodes.contains(barcode)) {
if (include) {
return false;
}
barcodes.remove(barcode);
} else {
if (!include) {
return false;
}
barcodes.add(barcode);
}
final _BarcodeList newList = _BarcodeList.now(barcodes);
_put(_getKey(productList), newList);
return true;
}