Flutter-Ernaehrungsapp/lib/models/food.dart

41 lines
1.1 KiB
Dart

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)'];
}
late int _id;
late String _name;
late String _foodGroup;
late int _calories;
late double _fatg;
late double _proteing;
late double _carbohydrateg;
late double _sugarsg;
late double _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;
}
}