push method

Future<void> push(
  1. ProductList productList,
  2. String barcode
)

Moves a barcode to the end of the list.

One barcode duplicate is potentially removed:

  • If the barcode was already there, it's moved to the end of the list.
  • If the barcode wasn't there, it's added to the end of the list.

Implementation

Future<void> push(ProductList productList, String barcode) async {
  final _BarcodeList? list = await _get(productList);
  final List<String> barcodes;
  if (list == null) {
    barcodes = <String>[];
  } else {
    barcodes = _getSafeBarcodeListCopy(list.barcodes);
  }
  barcodes.remove(barcode); // removes a potential duplicate
  barcodes.add(barcode);
  final _BarcodeList newList = _BarcodeList.now(barcodes);
  await _put(getKey(productList), newList);
}