refatcor(diary): Refactored (doesn't work yet though)

This commit is contained in:
2024-07-11 14:35:29 +03:00
parent def95aeeb5
commit e4cde31d76
27 changed files with 2304 additions and 1712 deletions

View File

@@ -12,25 +12,33 @@ class DiaryModel with _$DiaryModel {
required DateTime retire,
required int closed,
required String comment,
required List<Meals> meals}) = _DiaryModel;
required List<Meal> meals}) = _DiaryModel;
factory DiaryModel.fromJson(Map<String, Object?> json) => _$DiaryModelFromJson(json);
factory DiaryModel.fromJson(Map<String, Object?> json) =>
_$DiaryModelFromJson(json);
}
class Meals {
int? id;
String? time;
int? type;
int? satiety;
int? mood;
List<Portions>? portions;
List<Photos>? photos;
class Meal {
late int id;
late String time;
late int type;
late int satiety;
late int mood;
List<Portion>? portions;
List<Photo>? photos;
Meals({this.id, this.time, this.type, this.satiety, this.mood, this.portions, this.photos});
Meal(
{required this.id,
required this.time,
required this.type,
required this.satiety,
required this.mood,
this.portions,
this.photos});
Meals.fromJson(Map<String, dynamic> json) {
List<Portions> portions = [];
List<Photos> photos = [];
Meal.fromJson(Map<String, dynamic> json) {
List<Portion> portions = [];
List<Photo> photos = [];
id = json['id'];
time = json['time'];
type = json['type'];
@@ -38,12 +46,12 @@ class Meals {
mood = json['mood'];
if (json['portions'] != null) {
json['portions'].forEach((v) {
portions.add(new Portions.fromJson(v));
portions.add(new Portion.fromJson(v));
});
}
if (json['photos'] != null) {
json['photos'].forEach((v) {
photos.add(new Photos.fromJson(v));
photos.add(new Photo.fromJson(v));
});
}
}
@@ -65,20 +73,19 @@ class Meals {
}
}
class Portions {
int? id;
String? productName;
int? quantity;
String? portion;
class Portion {
late int id;
late String productName;
late int quantity;
late String portion;
Portions({this.id, this.productName, this.quantity, this.portion});
Portion(
{required this.id,
required this.productName,
required this.quantity,
required this.portion});
Portions.fromJson(Map<String, dynamic> json) {
id = json['id'];
productName = json['product_name'];
quantity = json['quantity'];
portion = json['portion'];
}
Portion.fromJson(v);
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
@@ -90,15 +97,19 @@ class Portions {
}
}
class Photos {
int? id;
String? originalName;
String? path;
int? size;
class Photo {
late int id;
late String originalName;
late String path;
late int size;
Photos({this.id, this.originalName, this.path, this.size});
Photo(
{required this.id,
required this.originalName,
required this.path,
required this.size});
Photos.fromJson(Map<String, dynamic> json) {
Photo.fromJson(Map<String, dynamic> json) {
id = json['id'];
originalName = json['original_name'];
path = json['path'];