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
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue