countProductLookedUp method
- String barcode
No-op for the barcode the page before it already counted. Both values
are written before the first await, so a caller that reads them right
after, without awaiting, already sees the new count and barcode.
Implementation
Future<void> countProductLookedUp(String barcode) async {
if (barcode == lastCountedBarcode) {
return;
}
final Future<bool> countSaved = _sharedPreferences.setInt(
_TAG_PRODUCTS_LOOKED_UP_SINCE_ASK,
productsLookedUpSinceAsk + 1,
);
final Future<bool> barcodeSaved = _sharedPreferences.setString(
_TAG_LAST_COUNTED_BARCODE,
barcode,
);
await countSaved;
await barcodeSaved;
}