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

@ -47,4 +47,22 @@ void main() {
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
});
}