Food, sync and warmer updates from 2026-10-26
- Food: "All products" lists what's here first (My foods, the food database, kept products), then Open Food Facts; the start of a barcode (4+ digits) finds the products starting with it (dashboard, app, server search). - Food: My foods barcodes; entries follow edits of their food or meal, and meals made with a changed food are worked out again (nested meals too); a save that changes nothing isn't written. - Food: the week strip shows protein / carbs / fat per day, over-target calories in red; the header's arrows go by week, days swap in place with prefetch on hover; the app's arrows go by week, a sideways swipe by day. - Food search: stomach / žalúdok / pipotă find gizzards, kurací / pui chicken, morčací / curcan turkey. - Sync: tables a plugin makes after start-up are prepared at the next sync and their file read from the start once. - Warmers build pages as each admin account and wait while someone is using the dashboard; slow page builds are logged. - Stations: impossible sensor readings are dropped; chart ticks never fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fb3c01cdd7
commit
4193de4262
26 changed files with 704 additions and 111 deletions
|
|
@ -13,6 +13,36 @@ What changed in each published build of the app. `tool/publish.sh` shows the ent
|
|||
- The band's data goes with the phone's time zone, so the dashboard reads its times right without a
|
||||
setting.
|
||||
|
||||
## 1.1.6 — 2026-10-26
|
||||
|
||||
- Food: the arrows at the top go a week back / ahead; swiping sideways goes a day. The dashboard's arrows go
|
||||
by week too.
|
||||
|
||||
## 1.1.5 — 2026-10-26
|
||||
|
||||
- Food: "All products" lists everything — My foods, the food database and products you kept first, then
|
||||
Open Food Facts. The dashboard does the same.
|
||||
- Food: the start of a barcode (4+ digits) finds the products whose barcode starts with it, in the search box
|
||||
and in all products.
|
||||
- Food: a meal made with a food you change is worked out again (and the meals made with that meal), its
|
||||
logged entries too.
|
||||
- Food: "stomach", "žalúdky" or "pipote" find gizzards; kurací / pui find chicken, morčací / curcan turkey.
|
||||
|
||||
## 1.1.4 — 2026-10-26
|
||||
|
||||
- Food: My foods can have a barcode (the food editor, with a scan button). Scanning it, or typing it in the
|
||||
search box, finds that food first.
|
||||
- Food: a barcode nothing is found for offers "New food with barcode …", which opens the editor with the
|
||||
barcode filled in. The dashboard does the same.
|
||||
- Food: the week strip's day pills show the day's protein / carbs / fat in their colours (by their share of the
|
||||
energy), and a day over its target has its calories in red. The dashboard does the same.
|
||||
|
||||
## 1.1.3 — 2026-10-26
|
||||
|
||||
- Food: editing a meal (its ingredients, weight when done) or one of My foods (its values or name) now
|
||||
updates every entry logged with it, for that entry's grams — already-logged days included. The
|
||||
dashboard does the same.
|
||||
|
||||
## 1.1.2 — 2026-10-23
|
||||
|
||||
- Work: grips at the top and bottom of a block — hold one and drag to start earlier / later or end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Every Open Food Facts product (2 million+, every country), searched on the sync server's archive
|
||||
// (GET /v1/food/search — sync-server/src/food.php), with filters: country, brand, Nutri-Score; a
|
||||
// barcode finds that product. A pick is kept ("food.product", food_model.dart keepProduct) and synced,
|
||||
// All products: what's here first (My foods, the food database, kept products), then every Open Food Facts
|
||||
// product (2 million+, every country), searched on the sync server's archive (GET /v1/food/search —
|
||||
// sync-server/src/food.php), with filters: country, brand, Nutri-Score; a barcode (or its first 4+ digits)
|
||||
// finds those products. A pick is kept ("food.product", food_model.dart keepProduct) and synced,
|
||||
// so entries made from it work on every device. Also the camera barcode scanner (ZXing, no Google services).
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
|
@ -14,6 +15,7 @@ import '../app/scanner.dart';
|
|||
import '../app/sync_service.dart';
|
||||
import '../app/theme.dart';
|
||||
import 'food_model.dart';
|
||||
import 'sugar.dart' show fold;
|
||||
|
||||
const _countries = [('', 'Any country'), ('ro', 'Romania'), ('sk', 'Slovakia'), ('cz', 'Czechia'), ('hu', 'Hungary'), ('at', 'Austria'),
|
||||
('de', 'Germany'), ('pl', 'Poland'), ('it', 'Italy'), ('fr', 'France'), ('es', 'Spain'), ('uk', 'UK'), ('us', 'USA')];
|
||||
|
|
@ -57,6 +59,7 @@ class _ArchiveSheetState extends State<ArchiveSheet> {
|
|||
late final q = TextEditingController(text: widget.q);
|
||||
final brand = TextEditingController();
|
||||
String country = '', score = '';
|
||||
List<Food> here = []; // My foods, the food database, kept products (no filters on)
|
||||
List<Map<String, dynamic>> items = [];
|
||||
String? status;
|
||||
Timer? timer;
|
||||
|
|
@ -81,30 +84,48 @@ class _ArchiveSheetState extends State<ArchiveSheet> {
|
|||
|
||||
Future<void> _run() async {
|
||||
final text = q.text.trim(), n = ++seq;
|
||||
final code = RegExp(r'^\d{8,14}$').hasMatch(text);
|
||||
final code = RegExp(r'^\d{4,14}$').hasMatch(text);
|
||||
if (!code && text.length < 3 && brand.text.trim().isEmpty && country.isEmpty) {
|
||||
setState(() {
|
||||
here = [];
|
||||
items = [];
|
||||
status = 'Type at least 3 letters, or pick a filter.';
|
||||
});
|
||||
return;
|
||||
}
|
||||
setState(() => status = 'Searching…');
|
||||
final store = widget.sync.store;
|
||||
final filtered = brand.text.trim().isNotEmpty || country.isNotEmpty || score.isNotEmpty; // the archive's facts
|
||||
final found = filtered
|
||||
? <Food>[]
|
||||
: code
|
||||
? [...myFoodsByBarcode(store, text, prefix: true).take(8), ...(widget.fdb?.byBarcode(text, prefix: true) ?? keptByBarcode(store, text, prefix: true)).take(8)]
|
||||
: text.length >= 3
|
||||
? () {
|
||||
final kept = keptProducts(store, text, fold: fold);
|
||||
return [...myFoods(store, text, limit: 6), ...kept,
|
||||
...(widget.fdb?.search(text, limit: 12) ?? []).where((f) => !kept.any((k) => k.foodId == f.foodId)).take(8)];
|
||||
}()
|
||||
: <Food>[];
|
||||
setState(() {
|
||||
here = found;
|
||||
status = 'Searching…';
|
||||
});
|
||||
try {
|
||||
final got = await archiveSearch(widget.sync, {
|
||||
if (code) 'barcode': text else 'q': text,
|
||||
'country': country, 'brand': brand.text.trim(), 'nutriscore': score,
|
||||
});
|
||||
if (!mounted || n != seq) return;
|
||||
final ids = {for (final f in here) if (f.foodId != null) f.foodId};
|
||||
setState(() {
|
||||
items = got;
|
||||
status = got.isEmpty ? 'Nothing found.' : null;
|
||||
items = [for (final it in got) if (!ids.contains((it['id'] as num).toInt())) it];
|
||||
status = items.isEmpty && here.isEmpty ? 'Nothing found.' : null;
|
||||
});
|
||||
} catch (e) {
|
||||
if (mounted && n == seq) {
|
||||
setState(() {
|
||||
items = [];
|
||||
status = '$e';
|
||||
status = here.isEmpty ? '$e' : 'Only what\'s here — $e';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -149,7 +170,8 @@ class _ArchiveSheetState extends State<ArchiveSheet> {
|
|||
padding: const EdgeInsets.fromLTRB(16, 14, 16, 12),
|
||||
child: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.stretch, children: [
|
||||
const Text('All products', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: accent)),
|
||||
const Text('Open Food Facts — every country, through the sync server', style: TextStyle(color: muted, fontSize: 12.5)),
|
||||
const Text('Yours and the food database first, then Open Food Facts — every country, through the sync server',
|
||||
style: TextStyle(color: muted, fontSize: 12.5)),
|
||||
const SizedBox(height: 6),
|
||||
TextField(
|
||||
controller: q,
|
||||
|
|
@ -188,6 +210,24 @@ class _ArchiveSheetState extends State<ArchiveSheet> {
|
|||
if (status != null) Padding(padding: const EdgeInsets.only(top: 10), child: Text(status!, style: const TextStyle(color: muted))),
|
||||
Flexible(
|
||||
child: ListView(shrinkWrap: true, children: [
|
||||
for (final f in here)
|
||||
ListTile(
|
||||
dense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(f.name, maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
subtitle: Text(
|
||||
[
|
||||
f.kind == 'my' ? (f.isMeal ? 'meal' : 'My foods') : (f.brand ?? '').isNotEmpty ? f.brand! : 'food database',
|
||||
if (f.kind != 'my') '✓ you have it',
|
||||
if (RegExp(r'^\d+$').hasMatch(q.text.trim()) && f.barcode != null) f.barcode!,
|
||||
].join(' · '),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(color: muted),
|
||||
),
|
||||
trailing: Text('${(f.per100['kcal'] ?? 0).round()} kcal', style: const TextStyle(fontSize: 13.5)),
|
||||
onTap: () => Navigator.of(context).pop(f),
|
||||
),
|
||||
for (final it in items)
|
||||
ListTile(
|
||||
dense: true,
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import 'package:sqlite3/sqlite3.dart';
|
|||
import '../sync/store.dart';
|
||||
import 'body_model.dart' show BodyView, bmrMifflin, female, profileOf;
|
||||
import 'cycle_model.dart' show iso;
|
||||
import 'sugar.dart' show fold;
|
||||
import 'summaries.dart';
|
||||
|
||||
const mealKeys = ['breakfast', 'lunch', 'dinner', 'snack'];
|
||||
|
|
@ -157,10 +158,25 @@ class FoodDb {
|
|||
return r != null ? _food(r) : store == null ? null : keptProduct(store!, id);
|
||||
}
|
||||
|
||||
/// The products with that barcode (foods.db keeps it as on the pack), else kept ones.
|
||||
List<Food> byBarcode(String code) {
|
||||
final rs = db.select("SELECT * FROM food WHERE barcode = ? OR barcode = ?", [code, code.replaceFirst(RegExp(r'^0+'), '')]);
|
||||
return rs.isNotEmpty ? [for (final r in rs) _food(r)] : store == null ? [] : keptByBarcode(store!, code);
|
||||
/// The products with that barcode (foods.db keeps it as on the pack), else kept ones; [prefix]: the ones whose
|
||||
/// barcode starts with [code] (a part typed), an exact one first (fooddb.by_barcode).
|
||||
List<Food> byBarcode(String code, {bool prefix = false}) {
|
||||
final bare = code.replaceFirst(RegExp(r'^0+'), '');
|
||||
final rs = prefix // a range, so the barcode index does it (digits; ':' follows '9')
|
||||
? db.select("SELECT * FROM food WHERE (barcode >= ? AND barcode < ?) OR (barcode >= ? AND barcode < ?) "
|
||||
"ORDER BY barcode IN (?, ?) DESC, barcode LIMIT 20", [code, '$code:', bare, '$bare:', code, bare])
|
||||
: db.select("SELECT * FROM food WHERE barcode = ? OR barcode = ?", [code, bare]);
|
||||
return rs.isNotEmpty ? [for (final r in rs) _food(r)] : store == null ? [] : keptByBarcode(store!, code, prefix: prefix);
|
||||
}
|
||||
|
||||
/// A word's start → the database's words for it too (fooddb.SAME: Slovak žalúdok / kurací / morčací,
|
||||
/// Romanian pipotă / pui / curcan).
|
||||
static const _same = {'stomach': ['gizzard'], 'zalud': ['gizzard', 'stomach'], 'pipot': ['gizzard'],
|
||||
'kurac': ['chicken'], 'pui': ['chicken'], 'morc': ['turkey'], 'curcan': ['turkey']};
|
||||
|
||||
static List<String> _alts(String w) {
|
||||
final f = fold(w);
|
||||
return [w, for (final e in _same.entries) if (f.startsWith(e.key)) ...e.value];
|
||||
}
|
||||
|
||||
/// fooddb.search: every word a prefix in name / brand / category; all in the name first, the name starting
|
||||
|
|
@ -168,7 +184,7 @@ class FoodDb {
|
|||
List<Food> search(String q, {int limit = 10}) {
|
||||
final ws = words(q);
|
||||
if (ws.isEmpty) return [];
|
||||
final terms = ws.map((w) => '"$w"*').join(' ');
|
||||
final terms = ws.map((w) => '(${_alts(w).map((x) => '"$x"*').join(' OR ')})').join(' AND ');
|
||||
final rs = db.select(
|
||||
'SELECT f.*, bm25(food_fts, 10, 1) AS rank FROM food_fts JOIN food f ON f.id = food_fts.rowid '
|
||||
'WHERE food_fts MATCH ? ORDER BY rank LIMIT 200', [terms]);
|
||||
|
|
@ -179,7 +195,7 @@ class FoodDb {
|
|||
final lead = nameWords.isEmpty ? '' : nameWords.first;
|
||||
final exact = (lead == first || lead == '${first}s' || lead == '${first}es' || first == '${lead}s' || first == '${lead}es')
|
||||
? 0 : lead.startsWith(first) ? 1 : 2;
|
||||
final inName = ws.every((w) => nameWords.any((x) => x.startsWith(w))) ? 0 : 1;
|
||||
final inName = ws.every((w) => nameWords.any((x) => _alts(w).any(x.startsWith))) ? 0 : 1;
|
||||
final plain = nameWords.any(_plain.contains) ? 0 : 1;
|
||||
return [inName, exact, plain, nameWords.length, ((r['rank'] as num) * 10).round() / 10, name.length,
|
||||
_rank[r['source']] ?? 3];
|
||||
|
|
@ -208,6 +224,7 @@ Food myFood(Map<String, dynamic> r) {
|
|||
final ps = (jsonDecode((r['portions'] as String?) ?? '[]') as List).cast<Map<String, dynamic>>();
|
||||
return Food(
|
||||
ref: 'my:${r['_u']}', kind: 'my', name: r['name'] as String, category: 'My foods', myUid: r['_u'] as String,
|
||||
barcode: r['barcode'] as String?,
|
||||
per100: {for (final c in foodCols) c: (r[c] as num?)?.toDouble()},
|
||||
portions: [for (final p in ps) Portion(p['label'] as String, (p['grams'] as num).toDouble())],
|
||||
isMeal: r['recipe'] != null,
|
||||
|
|
@ -238,6 +255,18 @@ List<Food> myFoods(SyncStore store, String q, {int limit = 8}) {
|
|||
return all.take(limit).map(myFood).toList();
|
||||
}
|
||||
|
||||
/// My foods (not deleted) with that barcode — as typed, or without its leading zeros (db.my_foods_by_barcode);
|
||||
/// [prefix]: the ones whose barcode starts with [code] (a part typed), an exact one first.
|
||||
List<Food> myFoodsByBarcode(SyncStore store, String code, {bool prefix = false}) {
|
||||
String bare(String c) => c.replaceFirst(RegExp(r'^0+'), '');
|
||||
bool hit(String b) => prefix ? b.startsWith(code) || bare(b).startsWith(bare(code)) : b == code || bare(b) == bare(code);
|
||||
final rs = [
|
||||
for (final r in store.rows('food.food'))
|
||||
if ((r['gone'] ?? 0) == 0 && r['barcode'] is String && hit(r['barcode'] as String)) r
|
||||
]..sort((a, b) => (a['barcode'] == code ? 0 : 1).compareTo(b['barcode'] == code ? 0 : 1));
|
||||
return rs.map(myFood).toList();
|
||||
}
|
||||
|
||||
Food? myFoodByUid(SyncStore store, String uid) {
|
||||
final r = store.row('food.food', uid);
|
||||
return r == null ? null : myFood(r);
|
||||
|
|
@ -339,8 +368,10 @@ Food? _kept(Map<String, dynamic>? row) {
|
|||
|
||||
Food? keptProduct(SyncStore store, int id) => _kept(store.row(tProduct, 'p:$id'));
|
||||
|
||||
List<Food> keptByBarcode(SyncStore store, String code) =>
|
||||
[for (final r in store.rows(tProduct, where: "json_extract(data, '\$.barcode') = ?", args: [code])) ?_kept(r)];
|
||||
List<Food> keptByBarcode(SyncStore store, String code, {bool prefix = false}) => [
|
||||
for (final r in store.rows(tProduct, where: "json_extract(data, '\$.barcode') ${prefix ? 'LIKE' : '='} ?", args: [prefix ? '$code%' : code]))
|
||||
?_kept(r)
|
||||
];
|
||||
|
||||
/// Kept products whose name / brand has every word of [q] (folded: no diacritics).
|
||||
List<Food> keptProducts(SyncStore store, String q, {required String Function(String) fold, int limit = 4}) {
|
||||
|
|
@ -388,7 +419,7 @@ Food? foodOf(SyncStore store, FoodDb? fdb, Entry e) {
|
|||
}
|
||||
|
||||
/// Save an entry made from [food] (amount × unit → grams → its nutrients) — new (u null) or changed.
|
||||
/// The numbers are the entry's own, worked out now (later changes to the food don't touch it).
|
||||
/// The numbers are the entry's own, worked out now; edits to one of My foods re-work them (_follow).
|
||||
String? saveFromFood(SyncStore store, {String? u, required String day, required String meal, required Food food,
|
||||
required double amount, required String unit, String note = ''}) {
|
||||
final g = food.grams(amount, unit);
|
||||
|
|
@ -522,8 +553,9 @@ const foodFields = {
|
|||
/// New (uid null) or changed food: name unique among the live ones, energy required, portions need a
|
||||
/// name + grams. The nutrients the editor doesn't show stay as they were. → (uid, error).
|
||||
/// [sugarKind]: "Sugar counts as" (added / dairy / natural; '' = estimated; null = left as it is).
|
||||
/// [barcode]: the pack's, 8–14 digits ('' = none; null = left as it is).
|
||||
(String?, String?) saveMyFood(SyncStore store, {String? uid, required String name, required Map<String, double?> per100,
|
||||
required List<Portion> portions, String note = '', String? sugarKind}) {
|
||||
required List<Portion> portions, String note = '', String? sugarKind, String? barcode}) {
|
||||
final n = name.trim().split(RegExp(r'\s+')).join(' ');
|
||||
if (n.isEmpty) return (null, 'Name the food.');
|
||||
if (per100['kcal'] == null) return (null, 'Energy per 100 g — from the label.');
|
||||
|
|
@ -538,20 +570,84 @@ const foodFields = {
|
|||
final clash = store.rows('food.food').any((r) =>
|
||||
(r['gone'] ?? 0) == 0 && r['_u'] != uid && (r['name'] as String).toLowerCase() == n.toLowerCase());
|
||||
if (clash) return (null, 'You already have a food with that name in My foods — pick it, or name this one differently.');
|
||||
final code = barcode?.replaceAll(RegExp(r'\s'), '');
|
||||
if (code != null && code.isNotEmpty) {
|
||||
if (!RegExp(r'^\d{8,14}$').hasMatch(code)) return (null, 'A barcode is 8–14 digits.');
|
||||
final other = myFoodsByBarcode(store, code).where((f) => f.myUid != uid);
|
||||
if (other.isNotEmpty) return (null, '“${other.first.name}” in My foods has that barcode already.');
|
||||
}
|
||||
final now = DateTime.now().toIso8601String().substring(0, 19);
|
||||
final old = uid == null ? null : store.row('food.food', uid);
|
||||
final u = uid ?? SyncStore.randomId();
|
||||
store.put('food.food', u, {
|
||||
final next = <String, dynamic>{
|
||||
'based_on': null, 'based_on_name': null, 'recipe': null, 'gone': 0, 'created': now,
|
||||
for (final c in foodCols) c: null,
|
||||
...?old,
|
||||
'name': n, ...per100, 'note': note.trim(), 'updated': now,
|
||||
if (sugarKind != null) 'sugar_kind': const ['added', 'dairy', 'natural'].contains(sugarKind) ? sugarKind : null,
|
||||
if (code != null) 'barcode': code.isEmpty ? null : code,
|
||||
'portions': jsonEncode([for (final p in portions) {'label': p.label.trim().split(RegExp(r'\s+')).join(' '), 'grams': p.grams}]),
|
||||
});
|
||||
};
|
||||
if (old != null && next.entries.every((e) => e.key == 'updated' || old[e.key] == e.value)) return (u, null); // nothing changed
|
||||
store.put('food.food', u, next);
|
||||
if (old != null) {
|
||||
_follow(store, u);
|
||||
_followMeals(store, u);
|
||||
}
|
||||
return (u, null);
|
||||
}
|
||||
|
||||
int _mealDepth = 0; // _followMeals inside _followMeals (a meal in a meal …)
|
||||
|
||||
/// The meals made with one of My foods follow its edits too: worked out again from their recipes (saveMeal, the
|
||||
/// ingredients as they are now — their entries follow), then the meals made with those (saveMyFood calls this
|
||||
/// again). One that can't be — an ingredient gone, or the food database not open yet — stays as it was
|
||||
/// (db.follow_meals).
|
||||
void _followMeals(SyncStore store, String uid) {
|
||||
if (_mealDepth >= 5) return;
|
||||
_mealDepth++;
|
||||
try {
|
||||
for (final m in store.rows('food.food')) {
|
||||
if ((m['gone'] ?? 0) != 0 || m['recipe'] is! String || m['_u'] == uid) continue;
|
||||
final refs = [
|
||||
for (final i in ((jsonDecode(m['recipe'] as String) as Map)['ingredients'] as List? ?? []))
|
||||
if ((i as Map)['food'] is String) i['food'] as String
|
||||
];
|
||||
if (!refs.any((r) => r.replaceFirst('~', '') == 'my:$uid')) continue;
|
||||
final fdb = FoodDb._one;
|
||||
final ok = refs.every((r) => r.startsWith('usda:') ? fdb?.food(int.tryParse(r.substring(5)) ?? -1) != null
|
||||
: r.startsWith('my:') ? myFoodByUid(store, r.substring(3).replaceFirst('~', '')) != null : false);
|
||||
if (!ok) continue;
|
||||
saveMeal(store, uid: m['_u'] as String, name: m['name'] as String, ings: recipeOf(store, fdb, m), doneGrams: doneGramsOf(m),
|
||||
portions: [
|
||||
for (final p in (jsonDecode((m['portions'] as String?) ?? '[]') as List).cast<Map>())
|
||||
Portion(p['label'] as String, (p['grams'] as num).toDouble())
|
||||
],
|
||||
note: (m['note'] as String?) ?? '');
|
||||
}
|
||||
} finally {
|
||||
_mealDepth--;
|
||||
}
|
||||
}
|
||||
|
||||
/// The entries logged from one of My foods follow its edits (a meal's recipe, a food's values or name):
|
||||
/// worked out again for their grams — only the ones that change, so the rest aren't re-sent (db._follow).
|
||||
void _follow(SyncStore store, String uid) {
|
||||
final f = store.row('food.food', uid);
|
||||
if (f == null) return;
|
||||
for (final e in store.rows('food.entry', where: "json_extract(data, '\$.my_food_id') = ?", args: [uid])) {
|
||||
final g = (e['grams'] as num?)?.toDouble();
|
||||
if (g == null || g <= 0) continue;
|
||||
final next = <String, dynamic>{
|
||||
for (final c in foodCols) c: f[c] == null ? null : ((f[c] as num) * g / 100 * 100).round() / 100,
|
||||
'name': f['name'],
|
||||
};
|
||||
if (next.entries.any((x) => e[x.key] != x.value)) {
|
||||
store.put('food.entry', e['_u'] as String, {...e, ...next});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Deleted foods are only hidden (gone): entries made from them keep pointing at them.
|
||||
void deleteMyFood(SyncStore store, String uid) {
|
||||
final r = store.row('food.food', uid);
|
||||
|
|
@ -708,8 +804,8 @@ Set<String> mealIds(SyncStore store, String uid, [int depth = 0]) {
|
|||
portions: [...portions.where((p) => p.label.trim().toLowerCase() != 'whole meal'), Portion('whole meal', (weight * 10).round() / 10)],
|
||||
note: note);
|
||||
if (err != null) return (null, err);
|
||||
final row = store.row('food.food', u!)!;
|
||||
store.put('food.food', u, {...row, 'recipe': jsonEncode({'ingredients': recipe, 'done_grams': doneGrams})});
|
||||
final row = store.row('food.food', u!)!, r = jsonEncode({'ingredients': recipe, 'done_grams': doneGrams});
|
||||
if (row['recipe'] != r) store.put('food.food', u, {...row, 'recipe': r});
|
||||
return (u, null);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,7 +92,18 @@ class _FoodPageState extends State<FoodPage> {
|
|||
label: Text(es.isEmpty ? 'Make a meal' : 'Make a meal (from this day’s entries)'),
|
||||
),
|
||||
];
|
||||
return ListView(padding: const EdgeInsets.fromLTRB(12, 10, 12, 24), children: [
|
||||
// the arrows go by week; a swipe sideways goes by day
|
||||
return GestureDetector(
|
||||
onHorizontalDragEnd: (e) {
|
||||
final v = e.primaryVelocity ?? 0;
|
||||
if (v.abs() < 300) return;
|
||||
if (v > 0) {
|
||||
setState(() => d = plus(d, -1));
|
||||
} else if (daysBetween(today(), d) < ahead) {
|
||||
setState(() => d = plus(d, 1));
|
||||
}
|
||||
},
|
||||
child: ListView(padding: const EdgeInsets.fromLTRB(12, 10, 12, 24), children: [
|
||||
if (wide)
|
||||
Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Expanded(child: Column(children: head)),
|
||||
|
|
@ -100,13 +111,14 @@ class _FoodPageState extends State<FoodPage> {
|
|||
Expanded(child: Column(children: meals)),
|
||||
])
|
||||
else ...[...head, const SizedBox(height: 10), ...meals],
|
||||
]);
|
||||
]),
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
Widget _nav() => Row(children: [
|
||||
IconButton(onPressed: () => setState(() => d = plus(d, -1)), icon: const Icon(Icons.chevron_left)),
|
||||
IconButton(tooltip: 'Week before', onPressed: () => setState(() => d = plus(d, -7)), icon: const Icon(Icons.chevron_left)),
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => setState(() => d = today()),
|
||||
|
|
@ -115,13 +127,15 @@ class _FoodPageState extends State<FoodPage> {
|
|||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: daysBetween(today(), d) < ahead ? () => setState(() => d = plus(d, 1)) : null,
|
||||
tooltip: 'Week after',
|
||||
onPressed: daysBetween(today(), d) + 7 <= ahead ? () => setState(() => d = plus(d, 7)) : null,
|
||||
icon: const Icon(Icons.chevron_right)),
|
||||
]);
|
||||
|
||||
Widget _week(double target) {
|
||||
final mon = plus(d, -(d.weekday - 1));
|
||||
final k = kcalByDay(widget.sync.store, dayIso(mon), dayIso(plus(mon, 6)));
|
||||
final m = dayTotals(widget.sync.store, dayIso(mon), dayIso(plus(mon, 6)));
|
||||
return Row(children: [
|
||||
for (var i = 0; i < 7; i++)
|
||||
() {
|
||||
|
|
@ -140,12 +154,13 @@ class _FoodPageState extends State<FoodPage> {
|
|||
const SizedBox(height: 3),
|
||||
Container(
|
||||
width: 12, height: 32, alignment: Alignment.bottomCenter,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(color: card2, borderRadius: BorderRadius.circular(3)),
|
||||
child: FractionallySizedBox(heightFactor: h / 1.15,
|
||||
child: Container(decoration: BoxDecoration(color: over ? bad : good, borderRadius: BorderRadius.circular(3)))),
|
||||
child: FractionallySizedBox(heightFactor: h / 1.15, child: _macroFill(m[dayIso(x)], kc)),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(kc == null ? '' : '${kc.round()}', style: const TextStyle(fontSize: 10.5, color: muted)),
|
||||
Text(kc == null ? '' : '${kc.round()}',
|
||||
style: TextStyle(fontSize: 10.5, color: over ? bad : muted, fontWeight: over ? FontWeight.bold : null)),
|
||||
]),
|
||||
),
|
||||
),
|
||||
|
|
@ -154,6 +169,20 @@ class _FoodPageState extends State<FoodPage> {
|
|||
]);
|
||||
}
|
||||
|
||||
/// A week pill's fill, bottom up: protein / carbs / fat by their share of the energy, the rest grey
|
||||
/// (views._macro_segs — as the History chart stacks them).
|
||||
Widget _macroFill(Map<String, double>? t, double? kcal) {
|
||||
if (t == null || kcal == null || kcal <= 0) return const SizedBox();
|
||||
final e = {for (final k in macros) k: (t[k] ?? 0) * kcalPerG[k]!};
|
||||
final total = max(kcal, e.values.fold<double>(0, (a, b) => a + b));
|
||||
final rest = total - e.values.fold<double>(0, (a, b) => a + b);
|
||||
return Column(children: [
|
||||
if (rest / total > 0.005) Expanded(flex: (rest / total * 1000).round(), child: Container(color: muted.withValues(alpha: 0.5))),
|
||||
for (final k in macros.reversed)
|
||||
if (e[k]! > 0) Expanded(flex: (e[k]! / total * 1000).round(), child: Container(color: macroColors[k])),
|
||||
]);
|
||||
}
|
||||
|
||||
Widget _meal(String m, List<Entry> es) {
|
||||
final t = totals(es);
|
||||
// a long-pressed food can be dropped on another meal's card (db.move: only the meal changes)
|
||||
|
|
|
|||
|
|
@ -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{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),
|
||||
|
|
@ -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,18 @@ 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); [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 …").
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
|
|||
|
||||
import '../app/sync_service.dart';
|
||||
import '../app/theme.dart';
|
||||
import 'food_archive.dart' show scanBarcode;
|
||||
import 'food_model.dart';
|
||||
import 'meal_builder.dart';
|
||||
|
||||
|
|
@ -82,20 +83,21 @@ class MyFoodsPage extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
|
||||
/// The editor as a bottom sheet; → the saved food's id (null = cancelled / deleted).
|
||||
Future<String?> openFoodEditor(BuildContext context, SyncService sync, {Map<String, dynamic>? row, String name = ''}) =>
|
||||
/// The editor as a bottom sheet; → the saved food's id (null = cancelled / deleted). [barcode]: a new food's,
|
||||
/// from a scan / typed barcode nothing was found for.
|
||||
Future<String?> openFoodEditor(BuildContext context, SyncService sync, {Map<String, dynamic>? row, String name = '', String barcode = ''}) =>
|
||||
showModalBottomSheet<String>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: card,
|
||||
builder: (_) => FoodEditor(sync: sync, row: row, name: name),
|
||||
builder: (_) => FoodEditor(sync: sync, row: row, name: name, barcode: barcode),
|
||||
);
|
||||
|
||||
class FoodEditor extends StatefulWidget {
|
||||
const FoodEditor({super.key, required this.sync, this.row, this.name = ''});
|
||||
const FoodEditor({super.key, required this.sync, this.row, this.name = '', this.barcode = ''});
|
||||
final SyncService sync;
|
||||
final Map<String, dynamic>? row;
|
||||
final String name;
|
||||
final String name, barcode;
|
||||
@override
|
||||
State<FoodEditor> createState() => _FoodEditorState();
|
||||
}
|
||||
|
|
@ -103,6 +105,7 @@ class FoodEditor extends StatefulWidget {
|
|||
class _FoodEditorState extends State<FoodEditor> {
|
||||
late final name = TextEditingController(text: widget.row?['name'] as String? ?? widget.name);
|
||||
late final note = TextEditingController(text: widget.row?['note'] as String? ?? '');
|
||||
late final barcode = TextEditingController(text: widget.row?['barcode'] as String? ?? widget.barcode);
|
||||
late String sugarKind = widget.row?['sugar_kind'] as String? ?? ''; // '' = estimated (sugar.dart)
|
||||
late final values = {
|
||||
for (final k in foodFields.keys)
|
||||
|
|
@ -127,7 +130,7 @@ class _FoodEditorState extends State<FoodEditor> {
|
|||
}
|
||||
final (uid, err) = saveMyFood(widget.sync.store, uid: widget.row?['_u'] as String?, name: name.text,
|
||||
per100: isMeal ? {for (final k in foodFields.keys) k: (widget.row![k] as num?)?.toDouble()} : {for (final e in values.entries) e.key: _n(e.value)},
|
||||
portions: ps, note: note.text, sugarKind: sugarKind);
|
||||
portions: ps, note: note.text, sugarKind: sugarKind, barcode: barcode.text);
|
||||
if (err != null) return setState(() => error = err);
|
||||
widget.sync.changed();
|
||||
Navigator.pop(context, uid);
|
||||
|
|
@ -142,6 +145,23 @@ class _FoodEditorState extends State<FoodEditor> {
|
|||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: accent)),
|
||||
TextField(controller: name, autofocus: widget.row == null && widget.name.isEmpty,
|
||||
decoration: const InputDecoration(labelText: 'Name')),
|
||||
if (!isMeal)
|
||||
TextField(
|
||||
controller: barcode,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Barcode',
|
||||
hintText: 'optional — scanning it finds this food',
|
||||
suffixIcon: IconButton(
|
||||
tooltip: 'Scan a barcode',
|
||||
icon: const Icon(Icons.qr_code_scanner),
|
||||
onPressed: () async {
|
||||
final code = await scanBarcode(context);
|
||||
if (code != null && mounted) setState(() => barcode.text = code);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(isMeal ? 'Per 100 g — from its ingredients (change them with the meal builder)' : 'Per 100 g (from the label)',
|
||||
style: const TextStyle(color: muted, fontSize: 13)),
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
|||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||
# In Windows, build-name is used as the major, minor, and patch parts
|
||||
# of the product and file versions while build-number is used as the build suffix.
|
||||
version: 1.1.2+5
|
||||
version: 1.1.6+10
|
||||
|
||||
environment:
|
||||
sdk: ^3.12.2
|
||||
|
|
|
|||
40
app/test/food_barcode_test.dart
Normal file
40
app/test/food_barcode_test.dart
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// My foods with the pack's barcode (food_model.dart saveMyFood / myFoodsByBarcode = the dashboard's db.clean_food /
|
||||
// my_foods_by_barcode): kept, found by it (leading zeros or not), checked, one food per barcode, left alone when not given.
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dash_app/health/food_model.dart';
|
||||
import 'package:dash_app/sync/store.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
final store = SyncStore('${Directory.systemTemp.createTempSync('barcode').path}/d.db', 'test00000000');
|
||||
|
||||
test('kept and found by it', () {
|
||||
final (u, err) = saveMyFood(store, name: 'Chicory syrup (4Slim)', per100: {'kcal': 161, 'fiber': 71}, portions: [],
|
||||
barcode: '8595245311155');
|
||||
expect(err, isNull);
|
||||
expect(myFoodsByBarcode(store, '8595245311155').single.myUid, u);
|
||||
expect(myFoodsByBarcode(store, '08595245311155').single.name, 'Chicory syrup (4Slim)');
|
||||
expect(myFoodByUid(store, u!)!.barcode, '8595245311155');
|
||||
expect(myFoodsByBarcode(store, '1234567890123'), isEmpty);
|
||||
});
|
||||
|
||||
test('checked: digits only, 8–14, one food per barcode', () {
|
||||
expect(saveMyFood(store, name: 'A', per100: {'kcal': 1}, portions: [], barcode: '12ab5678').$2, 'A barcode is 8–14 digits.');
|
||||
expect(saveMyFood(store, name: 'B', per100: {'kcal': 1}, portions: [], barcode: '1234567').$2, 'A barcode is 8–14 digits.');
|
||||
expect(saveMyFood(store, name: 'C', per100: {'kcal': 1}, portions: [], barcode: '8595245311155').$2, contains('has that barcode already'));
|
||||
});
|
||||
|
||||
test('an edit without it keeps it; empty clears it; a deleted food is not found', () {
|
||||
final u = myFoodsByBarcode(store, '8595245311155').single.myUid!;
|
||||
saveMyFood(store, uid: u, name: 'Chicory syrup (4Slim)', per100: {'kcal': 160}, portions: []);
|
||||
expect(store.row('food.food', u)!['barcode'], '8595245311155');
|
||||
saveMyFood(store, uid: u, name: 'Chicory syrup (4Slim)', per100: {'kcal': 160}, portions: [], barcode: ' 8595245311155 ');
|
||||
expect(store.row('food.food', u)!['barcode'], '8595245311155');
|
||||
deleteMyFood(store, u);
|
||||
expect(myFoodsByBarcode(store, '8595245311155'), isEmpty);
|
||||
final (v, _) = saveMyFood(store, name: 'D', per100: {'kcal': 1}, portions: [], barcode: '8595245311155');
|
||||
saveMyFood(store, uid: v, name: 'D', per100: {'kcal': 1}, portions: [], barcode: '');
|
||||
expect(store.row('food.food', v!)!['barcode'], isNull);
|
||||
});
|
||||
}
|
||||
68
app/test/food_follow_test.dart
Normal file
68
app/test/food_follow_test.dart
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
// Entries logged from one of My foods follow its edits (food_model.dart _follow = the dashboard's db._follow):
|
||||
// a meal's new recipe or a food's new values / name re-work them for their grams; others aren't touched.
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dash_app/health/food_model.dart';
|
||||
import 'package:dash_app/sync/store.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
final store = SyncStore('${Directory.systemTemp.createTempSync('follow').path}/d.db', 'test00000000');
|
||||
|
||||
test('editing a food re-works its entries', () {
|
||||
final (u, err) = saveMyFood(store, name: 'Tvaroh', per100: {'kcal': 200, 'protein': 14, 'fat': 15}, portions: []);
|
||||
expect(err, isNull);
|
||||
final f = myFoodByUid(store, u!)!;
|
||||
saveFromFood(store, u: 'e1', day: '2026-10-26', meal: 'lunch', food: f, amount: 100, unit: 'g');
|
||||
saveFromFood(store, u: 'e2', day: '2026-10-27', meal: 'lunch', food: f, amount: 150, unit: 'g');
|
||||
saveTotals(store, u: 'e3', day: '2026-10-27', meal: 'lunch', name: 'Tvaroh', values: {'kcal': 300});
|
||||
final h3 = store.rows('food.entry').firstWhere((r) => r['_u'] == 'e3')['_h'];
|
||||
|
||||
saveMyFood(store, uid: u, name: 'Tvaroh (homemade)', per100: {'kcal': 212, 'protein': 14, 'fat': 16}, portions: []);
|
||||
expect(store.row('food.entry', 'e1')!['kcal'], 212);
|
||||
expect(store.row('food.entry', 'e2')!['kcal'], 318);
|
||||
expect(store.row('food.entry', 'e2')!['fat'], 24);
|
||||
expect(store.row('food.entry', 'e2')!['name'], 'Tvaroh (homemade)');
|
||||
expect(store.row('food.entry', 'e3')!['kcal'], 300); // typed numbers, no food: left alone
|
||||
expect(store.rows('food.entry').firstWhere((r) => r['_u'] == 'e3')['_h'], h3);
|
||||
});
|
||||
|
||||
test('unchanged entries are not re-sent', () {
|
||||
final (u, _) = saveMyFood(store, name: 'Casein', per100: {'kcal': 390}, portions: []);
|
||||
saveFromFood(store, u: 'c1', day: '2026-10-26', meal: 'breakfast', food: myFoodByUid(store, u!)!, amount: 30, unit: 'g');
|
||||
final h = store.rows('food.entry').firstWhere((r) => r['_u'] == 'c1')['_h'];
|
||||
saveMyFood(store, uid: u, name: 'Casein', per100: {'kcal': 390}, portions: [], note: 'a note');
|
||||
expect(store.rows('food.entry').firstWhere((r) => r['_u'] == 'c1')['_h'], h);
|
||||
});
|
||||
|
||||
test('a meal’s new recipe re-works its entries', () {
|
||||
final (oil, _) = saveMyFood(store, name: 'Oil', per100: {'kcal': 900, 'fat': 100}, portions: []);
|
||||
final (veg, _) = saveMyFood(store, name: 'Veg', per100: {'kcal': 30, 'fat': 0}, portions: []);
|
||||
Ingredient ing(String uid, double g) => Ingredient.food(myFoodByUid(store, uid)!, g, 'g');
|
||||
final (soup, err) = saveMeal(store, name: 'Soup', ings: [ing(oil!, 30), ing(veg!, 970)], portions: []);
|
||||
expect(err, isNull);
|
||||
saveFromFood(store, u: 's1', day: '2026-10-27', meal: 'lunch', food: myFoodByUid(store, soup!)!, amount: 400, unit: 'g');
|
||||
expect(store.row('food.entry', 's1')!['kcal'], closeTo(400 * (27000 + 29100) / 100000, 0.01));
|
||||
|
||||
saveMeal(store, uid: soup, name: 'Soup', ings: [ing(oil, 10), ing(veg, 970)], portions: []);
|
||||
expect(store.row('food.entry', 's1')!['kcal'], closeTo(400 * (9000 + 29100) / 98000, 0.01));
|
||||
});
|
||||
|
||||
test('a meal made with a changed food is worked out again, its entries too', () {
|
||||
final (curd, _) = saveMyFood(store, name: 'Curd', per100: {'kcal': 100, 'protein': 12}, portions: []);
|
||||
final (flour, _) = saveMyFood(store, name: 'Flour', per100: {'kcal': 350}, portions: []);
|
||||
Ingredient ing(String uid, double g) => Ingredient.food(myFoodByUid(store, uid)!, g, 'g');
|
||||
final (strudel, _) = saveMeal(store, name: 'Strudel', ings: [ing(curd!, 300), ing(flour!, 200)], portions: []);
|
||||
final (plate, _) = saveMeal(store, name: 'Plate', ings: [ing(strudel!, 250), ing(flour, 50)], portions: []);
|
||||
saveFromFood(store, u: 'p1', day: '2026-10-27', meal: 'dinner', food: myFoodByUid(store, plate!)!, amount: 150, unit: 'g');
|
||||
expect(store.row('food.food', strudel)!['kcal'], closeTo((300 + 700) / 5, 0.001));
|
||||
final hFlour = store.row('food.food', flour)!['_h'];
|
||||
|
||||
saveMyFood(store, uid: curd, name: 'Curd', per100: {'kcal': 200, 'protein': 12}, portions: []);
|
||||
expect(store.row('food.food', strudel)!['kcal'], closeTo((600 + 700) / 5, 0.001));
|
||||
final plateKcal = (250 * 260 / 100 + 175) * 100 / 300;
|
||||
expect(store.row('food.food', plate)!['kcal'], closeTo(plateKcal, 0.001));
|
||||
expect(store.row('food.entry', 'p1')!['kcal'], closeTo(plateKcal * 1.5, 0.01));
|
||||
expect(store.row('food.food', flour)!['_h'], hFlour); // not an ingredient's meal: untouched
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue