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'];

View File

@@ -26,7 +26,7 @@ mixin _$DiaryModel {
DateTime get retire => throw _privateConstructorUsedError;
int get closed => throw _privateConstructorUsedError;
String get comment => throw _privateConstructorUsedError;
List<Meals> get meals => throw _privateConstructorUsedError;
List<Meal> get meals => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
@@ -47,7 +47,7 @@ abstract class $DiaryModelCopyWith<$Res> {
DateTime retire,
int closed,
String comment,
List<Meals> meals});
List<Meal> meals});
}
/// @nodoc
@@ -99,7 +99,7 @@ class _$DiaryModelCopyWithImpl<$Res, $Val extends DiaryModel>
meals: null == meals
? _value.meals
: meals // ignore: cast_nullable_to_non_nullable
as List<Meals>,
as List<Meal>,
) as $Val);
}
}
@@ -119,7 +119,7 @@ abstract class _$$DiaryModelImplCopyWith<$Res>
DateTime retire,
int closed,
String comment,
List<Meals> meals});
List<Meal> meals});
}
/// @nodoc
@@ -169,7 +169,7 @@ class __$$DiaryModelImplCopyWithImpl<$Res>
meals: null == meals
? _value._meals
: meals // ignore: cast_nullable_to_non_nullable
as List<Meals>,
as List<Meal>,
));
}
}
@@ -184,7 +184,7 @@ class _$DiaryModelImpl implements _DiaryModel {
required this.retire,
required this.closed,
required this.comment,
required final List<Meals> meals})
required final List<Meal> meals})
: _meals = meals;
factory _$DiaryModelImpl.fromJson(Map<String, dynamic> json) =>
@@ -202,9 +202,9 @@ class _$DiaryModelImpl implements _DiaryModel {
final int closed;
@override
final String comment;
final List<Meals> _meals;
final List<Meal> _meals;
@override
List<Meals> get meals {
List<Meal> get meals {
if (_meals is EqualUnmodifiableListView) return _meals;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_meals);
@@ -256,7 +256,7 @@ abstract class _DiaryModel implements DiaryModel {
required final DateTime retire,
required final int closed,
required final String comment,
required final List<Meals> meals}) = _$DiaryModelImpl;
required final List<Meal> meals}) = _$DiaryModelImpl;
factory _DiaryModel.fromJson(Map<String, dynamic> json) =
_$DiaryModelImpl.fromJson;
@@ -274,7 +274,7 @@ abstract class _DiaryModel implements DiaryModel {
@override
String get comment;
@override
List<Meals> get meals;
List<Meal> get meals;
@override
@JsonKey(ignore: true)
_$$DiaryModelImplCopyWith<_$DiaryModelImpl> get copyWith =>

View File

@@ -15,7 +15,7 @@ _$DiaryModelImpl _$$DiaryModelImplFromJson(Map<String, dynamic> json) =>
closed: (json['closed'] as num).toInt(),
comment: json['comment'] as String,
meals: (json['meals'] as List<dynamic>)
.map((e) => Meals.fromJson(e as Map<String, dynamic>))
.map((e) => Meal.fromJson(e as Map<String, dynamic>))
.toList(),
);