import 'package:fooder/models/meal.dart'; class Diary { final int id; final DateTime date; final List meals; final double calories; final double protein; final double carb; final double fat; final double fiber; Diary({ required this.id, required this.date, required this.meals, required this.calories, required this.protein, required this.carb, required this.fat, required this.fiber, }); Diary.fromJson(Map map) : id = map['id'] as int, date = DateTime.parse(map['date']), meals = (map['meals'] as List) .map((e) => Meal.fromJson(e as Map)) .toList(), calories = map['calories'] as double, protein = map['protein'] as double, carb = map['carb'] as double, fat = map['fat'] as double, fiber = map['fiber'] as double; Map toMap() { return { 'id': id, 'date': date.toIso8601String(), 'meals': meals.map((e) => e.toMap()).toList(), 'calories': calories, 'protein': protein, 'carb': carb, 'fat': fat, 'fiber': fiber, }; } }