fooder-app/lib/models/entry.dart

51 lines
1.2 KiB
Dart
Raw Permalink Normal View History

2023-07-30 15:31:36 +02:00
import 'package:fooder/models/product.dart';
2023-07-29 19:46:11 +02:00
2023-07-29 19:21:02 +02:00
class Entry {
2023-07-29 19:46:11 +02:00
final int id;
final double grams;
final Product product;
final int mealId;
2023-07-29 19:21:02 +02:00
final double calories;
final double protein;
final double fat;
2023-07-30 20:44:50 +02:00
final double fiber;
2023-07-29 19:21:02 +02:00
final double carb;
2023-07-29 20:55:32 +02:00
Entry({
2023-07-29 19:46:11 +02:00
required this.id,
required this.grams,
required this.product,
required this.mealId,
2023-07-29 19:21:02 +02:00
required this.calories,
required this.protein,
required this.fat,
2023-07-30 20:44:50 +02:00
required this.fiber,
2023-07-29 19:21:02 +02:00
required this.carb,
});
2023-07-29 23:54:51 +02:00
2023-08-28 14:45:32 +02:00
Entry.fromJson(Map<String, dynamic> map)
: id = map['id'] as int,
grams = map['grams'] as double,
product = Product.fromJson(map['product'] as Map<String, dynamic>),
mealId = map['meal_id'] as int,
calories = map['calories'] as double,
protein = map['protein'] as double,
fat = map['fat'] as double,
fiber = map['fiber'] as double,
carb = map['carb'] as double;
Map<String, Object?> toMap() {
return {
'id': id,
'grams': grams,
'product': product.toMap(),
'mealId': mealId,
'calories': calories,
'protein': protein,
'fat': fat,
'fiber': fiber,
'carb': carb,
};
}
2023-07-29 19:21:02 +02:00
}