push method Null safety

void push(
  1. dynamic 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

void push(final ProductList productList, final String barcode) {
  final _BarcodeList? list = _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);
  _put(_getKey(productList), newList);
}