Food: all products, barcode prefixes, meals that follow their ingredients

- "All products" lists what's here first (My foods, kept products, the food
  database), then Open Food Facts; if the archive can't be reached, what's
  here is still shown. A My food picked there is used as it is.
- The start of a barcode (4+ digits) finds the products whose barcode starts
  with it: in the search box, in all products and in the server's search
  (an index range, so it stays fast).
- A meal made with a changed food is worked out again, and so are meals made
  with that meal and their logged entries (db.follow_meals, app _followMeals).
- Saving a food that didn't change writes nothing, so nothing is synced again.
- Food search knows a few words in other languages: stomach / žalúdok /
  pipotă find gizzards, kurací / pui chicken, morčací / curcan turkey.
- App 1.1.5 changelog entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-10-26 15:41:23 +02:00
parent d9460a2293
commit eeca189b7f
11 changed files with 287 additions and 71 deletions

View file

@ -144,8 +144,8 @@ class _FoodSheetState extends State<FoodSheet> {
if (rest.isNotEmpty) sections.add(('Yesterday · other meals', [for (final e in rest) _yday(e, already(e))]));
final recent = recentFoods(store, '', limit: 8);
if (recent.isNotEmpty) sections.add(('Eaten often', [for (final (e, n) in recent) _recent(e, n)]));
} else if (RegExp(r'^\d{8,14}$').hasMatch(text)) { // a barcode: My foods with it, that product here or kept
final found = _byBarcode(text);
} else if (RegExp(r'^\d{4,14}$').hasMatch(text)) { // a barcode or its start: My foods, products here or kept
final found = _byBarcode(text, prefix: true);
sections.add(('Barcode $text', [
for (final f in found) _foodTile(f),
if (found.isEmpty) const Padding(padding: EdgeInsets.symmetric(vertical: 6),
@ -227,9 +227,11 @@ class _FoodSheetState extends State<FoodSheet> {
if (f != null && mounted) _pick(f);
}
/// My foods with that barcode first, then the food database's product (or a kept one).
List<Food> _byBarcode(String code) =>
[...myFoodsByBarcode(widget.sync.store, code), ...widget.fdb?.byBarcode(code) ?? keptByBarcode(widget.sync.store, code)];
/// My foods with that barcode first, then the food database's product (or a kept one); [prefix]: starting with it.
List<Food> _byBarcode(String code, {bool prefix = false}) => [
...myFoodsByBarcode(widget.sync.store, code, prefix: prefix),
...widget.fdb?.byBarcode(code, prefix: prefix) ?? keptByBarcode(widget.sync.store, code, prefix: prefix),
];
/// The camera → a barcode: My foods / its product here, else straight to the archive (nothing there either:
/// the box keeps the barcode, with "New food with barcode …").