Food: logged entries follow their food; barcodes for My foods
- Saving one of My foods or a meal works every entry logged from it out again for that entry's grams, on any day. Only the entries that change are written, so the rest aren't synced again (db._follow, app _follow). - My foods can have a barcode (8-14 digits, one food per barcode). A scanned or typed barcode finds My foods first (leading zeros ignored), then the food database and kept products; when nothing matches, "New food with barcode" opens the food editor with it filled in. - App 1.1.3 and 1.1.4 changelog entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fb3c01cdd7
commit
ad4b6aa22f
12 changed files with 238 additions and 30 deletions
|
|
@ -2,8 +2,9 @@
|
|||
// keyboard). Modes:
|
||||
// search — the box: empty = yesterday's foods (this meal first; + adds one as it was, a tap picks
|
||||
// it to change the portion); typed = My foods · Eaten before · Food database · Products
|
||||
// (+ ones kept from the archive); a barcode (typed or scanned — the camera button) = that
|
||||
// product; "Search all products…" = the archive on the sync server (food_archive.dart)
|
||||
// (+ ones kept from the archive); a barcode (typed or scanned — the camera button) = My foods
|
||||
// with it, else that product; nothing → "New food with barcode …" (it's kept with the food);
|
||||
// "Search all products…" = the archive on the sync server (food_archive.dart)
|
||||
// food — the picked food: amount + unit (g, ml, its portions, tbsp / tsp), the numbers live, meal
|
||||
// totals — an entry without a food (Lifesum imports, estimates): name, kcal / P / C / F
|
||||
// Editing an entry opens it in food or totals mode; Delete = tap twice.
|
||||
|
|
@ -143,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: that product, here or kept
|
||||
final found = widget.fdb?.byBarcode(text) ?? keptByBarcode(store, text);
|
||||
} else if (RegExp(r'^\d{8,14}$').hasMatch(text)) { // a barcode: My foods with it, that product here or kept
|
||||
final found = _byBarcode(text);
|
||||
sections.add(('Barcode $text', [
|
||||
for (final f in found) _foodTile(f),
|
||||
if (found.isEmpty) const Padding(padding: EdgeInsets.symmetric(vertical: 6),
|
||||
|
|
@ -194,12 +195,13 @@ class _FoodSheetState extends State<FoodSheet> {
|
|||
if (text.isNotEmpty)
|
||||
TextButton.icon(
|
||||
onPressed: () async {
|
||||
final uid = await openFoodEditor(context, widget.sync, name: text);
|
||||
final code = RegExp(r'^\d{8,14}$').hasMatch(text);
|
||||
final uid = await openFoodEditor(context, widget.sync, name: code ? '' : text, barcode: code ? text : '');
|
||||
final f = uid == null ? null : myFoodByUid(widget.sync.store, uid);
|
||||
if (f != null && mounted) _pick(f);
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
label: Text('New food “$text” (from its label)'),
|
||||
label: Text(RegExp(r'^\d{8,14}$').hasMatch(text) ? 'New food with barcode $text (from its label)' : 'New food “$text” (from its label)'),
|
||||
),
|
||||
if (text.isNotEmpty)
|
||||
TextButton.icon(
|
||||
|
|
@ -225,11 +227,16 @@ class _FoodSheetState extends State<FoodSheet> {
|
|||
if (f != null && mounted) _pick(f);
|
||||
}
|
||||
|
||||
/// The camera → a barcode: its product here, else straight to the archive.
|
||||
/// 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)];
|
||||
|
||||
/// 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 …").
|
||||
Future<void> _scan() async {
|
||||
final code = await scanBarcode(context);
|
||||
if (code == null || !mounted) return;
|
||||
final here = widget.fdb?.byBarcode(code) ?? keptByBarcode(widget.sync.store, code);
|
||||
final here = _byBarcode(code);
|
||||
if (here.length == 1) return _pick(here.first);
|
||||
setState(() => q.text = code);
|
||||
if (here.isEmpty) await _archive(code);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue