fooder-app/lib/models/product.dart

48 lines
1.2 KiB
Dart
Raw Permalink Normal View History

2023-07-29 19:46:11 +02:00
class Product {
final int id;
final String name;
final double calories;
final double protein;
final double carb;
final double fat;
2023-07-30 20:44:50 +02:00
final double fiber;
final int usageCountCached;
2024-08-03 22:30:07 +02:00
final String? barcode;
2023-07-29 19:46:11 +02:00
2024-08-03 22:30:07 +02:00
Product(
{required this.id,
required this.name,
required this.calories,
required this.protein,
required this.carb,
required this.fat,
required this.fiber,
this.usageCountCached = 0,
2024-08-03 22:30:07 +02:00
this.barcode});
2023-07-29 23:54:51 +02:00
2023-08-28 14:45:32 +02:00
Product.fromJson(Map<String, dynamic> map)
: id = map['id'] as int,
name = map['name'] as String,
calories = map['calories'] as double,
protein = map['protein'] as double,
carb = map['carb'] as double,
fat = map['fat'] as double,
2024-08-03 22:30:07 +02:00
fiber = map['fiber'] as double,
usageCountCached = map['usage_count_cached'] as int,
2024-08-03 22:30:07 +02:00
barcode = map['barcode'] as String?;
Map<String, Object?> toMap() {
return {
'id': id,
'name': name,
'calories': calories,
'protein': protein,
'carb': carb,
'fat': fat,
'fiber': fiber,
'barcode': barcode,
'usage_count_cached': usageCountCached,
2024-08-03 22:30:07 +02:00
};
}
2023-07-29 19:46:11 +02:00
}