feat: add support for alternative ingredients; implement JSON storage and parsing logic
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
This commit is contained in:
@@ -149,11 +149,21 @@ class _CreateRecipeScreenState extends ConsumerState<CreateRecipeScreen> {
|
||||
_parsed!.ingredients[i].quantity;
|
||||
final unit = _unitControllers[i]!.text.trim();
|
||||
final note = _noteControllers[i]!.text.trim();
|
||||
final ing = _parsed!.ingredients[i];
|
||||
// Alternativa produkter: alla suggestions vars productId matchar ett alternativ
|
||||
final alternativeProductIds = ing.alternatives.length > 1
|
||||
? ing.suggestions
|
||||
.where((s) => s.productId != productId)
|
||||
.map((s) => s.productId)
|
||||
.toList()
|
||||
: <int>[];
|
||||
ingredients.add({
|
||||
'productId': productId,
|
||||
'quantity': qty,
|
||||
'unit': unit,
|
||||
if (note.isNotEmpty) 'note': note,
|
||||
if (alternativeProductIds.isNotEmpty)
|
||||
'alternativeProductIds': alternativeProductIds,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -339,7 +349,19 @@ class _CreateRecipeScreenState extends ConsumerState<CreateRecipeScreen> {
|
||||
CheckboxListTile(
|
||||
value: isIncluded,
|
||||
onChanged: (v) => setState(() => _included[index] = v ?? false),
|
||||
title: Text(ing.rawName),
|
||||
title: ing.alternatives.length > 1
|
||||
? Wrap(
|
||||
spacing: 4,
|
||||
children: ing.alternatives
|
||||
.map((alt) => Chip(
|
||||
label: Text(alt),
|
||||
padding: EdgeInsets.zero,
|
||||
materialTapTargetSize:
|
||||
MaterialTapTargetSize.shrinkWrap,
|
||||
))
|
||||
.toList(),
|
||||
)
|
||||
: Text(ing.rawName),
|
||||
subtitle: noProductFound
|
||||
? Text(
|
||||
context.l10n.recipeCreateNoProductFound,
|
||||
|
||||
Reference in New Issue
Block a user