set method
- ProductList productList,
- String barcode,
- bool include
Adds or removes a barcode within a product list (depending on include)
Returns true if there was a change in the list.
Implementation
Future<bool> set(
ProductList productList,
String barcode,
bool include,
) async {
final _BarcodeList? list = await _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);
await _put(getKey(productList), newList);
return true;
}