Flutter-Ernaehrungsapp/lib/models/food.dart

59 lines
1.5 KiB
Dart

import 'package:hive/hive.dart';
part 'adapter/food.g.dart';
@HiveType(typeId: 1)
class Food {
Food(this.id, this.name, this.foodGroup, this.calories, this.fatg,
this.proteing, this.carbohydrateg, this.sugarsg, this.fiberg);
Food.fromJson(dynamic json) {
id = json['ID'];
name = json['name'];
foodGroup = json['Food Group'];
calories = json['Calories'];
fatg = json['Fat (g)'];
proteing = json['Protein (g)'];
carbohydrateg = json['Carbohydrate (g)'];
sugarsg = json['Sugars (g)'];
fiberg = json['Fiber (g)'];
}
@HiveField(0)
late dynamic id;
@HiveField(1)
late dynamic name;
@HiveField(2)
late dynamic foodGroup;
@HiveField(3)
late dynamic calories;
@HiveField(4)
late dynamic fatg;
@HiveField(5)
late dynamic proteing;
@HiveField(6)
late dynamic carbohydrateg;
@HiveField(7)
late dynamic sugarsg;
@HiveField(8)
late dynamic fiberg;
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['ID'] = id;
map['name'] = name;
map['Food Group'] = foodGroup;
map['Calories'] = calories;
map['Fat (g)'] = fatg;
map['Protein (g)'] = proteing;
map['Carbohydrate (g)'] = carbohydrateg;
map['Sugars (g)'] = sugarsg;
map['Fiber (g)'] = fiberg;
return map;
}
@override
String toString() {
return 'Food{id: $id, name: $name, foodGroup: $foodGroup, calories: $calories, fatg: $fatg, proteing: $proteing, carbohydrateg: $carbohydrateg, sugarsg: $sugarsg, fiberg: $fiberg}';
}
}