Files
davide eb7912421c feat: riscrivi app in Flutter
Riscrittura completa da Vue 3 + Capacitor a Flutter/Dart.

Architettura feature-based (lib/features/):
- meal_planner: modello MealPlan/DayPlan, provider, pagina e widget
- converter: modello ConversionEntry, provider con ricerca, pagina
- shopping_list: modello ShoppingItem, provider con deduplicazione, pagina e widget

Core:
- Material 3 con seed color #2d6a4f
- NavigationBar + IndexedStack (preserva stato dei tab)
- Portrait lock via SystemChrome
- Persistenza con shared_preferences
- 50+ alimenti × metodi cottura in assets/data/conversions.json

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 17:41:26 +02:00

82 lines
2.1 KiB
Dart

import 'dart:convert';
class DayPlan {
final List<String> colazione;
final List<String> pranzo;
final List<String> cena;
DayPlan({
List<String>? colazione,
List<String>? pranzo,
List<String>? cena,
}) : colazione = colazione ?? [],
pranzo = pranzo ?? [],
cena = cena ?? [];
DayPlan copyWith({
List<String>? colazione,
List<String>? pranzo,
List<String>? cena,
}) =>
DayPlan(
colazione: colazione ?? List.of(this.colazione),
pranzo: pranzo ?? List.of(this.pranzo),
cena: cena ?? List.of(this.cena),
);
List<String> slot(String name) => switch (name) {
'colazione' => colazione,
'pranzo' => pranzo,
'cena' => cena,
_ => const [],
};
Map<String, dynamic> toJson() => {
'colazione': colazione,
'pranzo': pranzo,
'cena': cena,
};
factory DayPlan.fromJson(Map<String, dynamic> json) => DayPlan(
colazione: List<String>.from(json['colazione'] ?? []),
pranzo: List<String>.from(json['pranzo'] ?? []),
cena: List<String>.from(json['cena'] ?? []),
);
}
class MealPlan {
final Map<String, DayPlan> days;
const MealPlan(this.days);
factory MealPlan.empty(List<String> dayIds) =>
MealPlan({for (final d in dayIds) d: DayPlan()});
MealPlan withUpdatedDay(String dayId, DayPlan updated) =>
MealPlan({...days, dayId: updated});
bool get hasAnyMeal => days.values.any(
(d) =>
d.colazione.isNotEmpty ||
d.pranzo.isNotEmpty ||
d.cena.isNotEmpty,
);
List<String> get allItems => days.values
.expand((d) => [...d.colazione, ...d.pranzo, ...d.cena])
.toList();
Map<String, dynamic> toJson() =>
{for (final e in days.entries) e.key: e.value.toJson()};
factory MealPlan.fromJson(Map<String, dynamic> json) => MealPlan({
for (final e in json.entries)
e.key: DayPlan.fromJson(e.value as Map<String, dynamic>),
});
String toJsonString() => jsonEncode(toJson());
factory MealPlan.fromJsonString(String s) =>
MealPlan.fromJson(jsonDecode(s) as Map<String, dynamic>);
}