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