forked from eatvio/eatvio_app
refactor(diary): API connect attempt
This commit is contained in:
19
lib/features/diary/models/diary,dart
Normal file
19
lib/features/diary/models/diary,dart
Normal file
@@ -0,0 +1,19 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'diary.freezed.dart';
|
||||
part 'diary.g.dart';
|
||||
|
||||
@freezed
|
||||
class Diary with _$Diary {
|
||||
const factory Diary({
|
||||
required int id,
|
||||
required DateTime date,
|
||||
required int closed,
|
||||
String? comment,
|
||||
DateTime? wakeup,
|
||||
DateTime? retire,
|
||||
}) = _Diary;
|
||||
|
||||
factory Diary.fromJson(Map<String, Object?> json) =>
|
||||
_$DiaryFromJson(json);
|
||||
}
|
||||
@@ -1,127 +1,21 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import './meal.dart';
|
||||
|
||||
part 'diary_model.freezed.dart';
|
||||
part 'diary_model.g.dart';
|
||||
|
||||
@freezed
|
||||
class DiaryModel with _$DiaryModel {
|
||||
const factory DiaryModel(
|
||||
{required int id,
|
||||
required DateTime date,
|
||||
required DateTime wakeup,
|
||||
required DateTime retire,
|
||||
required int closed,
|
||||
required String comment,
|
||||
required List<Meal> meals}) = _DiaryModel;
|
||||
const factory DiaryModel({
|
||||
required int id,
|
||||
required DateTime date,
|
||||
required int closed,
|
||||
required List<Meal>? meals,
|
||||
String? comment,
|
||||
DateTime? wakeup,
|
||||
DateTime? retire,
|
||||
}) = _DiaryModel;
|
||||
|
||||
factory DiaryModel.fromJson(Map<String, Object?> json) =>
|
||||
_$DiaryModelFromJson(json);
|
||||
}
|
||||
|
||||
class Meal {
|
||||
late int id;
|
||||
late String time;
|
||||
late int type;
|
||||
late int satiety;
|
||||
late int mood;
|
||||
List<Portion>? portions;
|
||||
List<Photo>? photos;
|
||||
|
||||
Meal(
|
||||
{required this.id,
|
||||
required this.time,
|
||||
required this.type,
|
||||
required this.satiety,
|
||||
required this.mood,
|
||||
this.portions,
|
||||
this.photos});
|
||||
|
||||
Meal.fromJson(Map<String, dynamic> json) {
|
||||
List<Portion> portions = [];
|
||||
List<Photo> photos = [];
|
||||
id = json['id'];
|
||||
time = json['time'];
|
||||
type = json['type'];
|
||||
satiety = json['satiety'];
|
||||
mood = json['mood'];
|
||||
if (json['portions'] != null) {
|
||||
json['portions'].forEach((v) {
|
||||
portions.add(new Portion.fromJson(v));
|
||||
});
|
||||
}
|
||||
if (json['photos'] != null) {
|
||||
json['photos'].forEach((v) {
|
||||
photos.add(new Photo.fromJson(v));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['id'] = this.id;
|
||||
data['time'] = this.time;
|
||||
data['type'] = this.type;
|
||||
data['satiety'] = this.satiety;
|
||||
data['mood'] = this.mood;
|
||||
if (this.portions != null) {
|
||||
data['portions'] = this.portions?.map((v) => v.toJson()).toList();
|
||||
}
|
||||
if (this.photos != null) {
|
||||
data['photos'] = this.photos?.map((v) => v.toJson()).toList();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class Portion {
|
||||
late int id;
|
||||
late String productName;
|
||||
late int quantity;
|
||||
late String portion;
|
||||
|
||||
Portion(
|
||||
{required this.id,
|
||||
required this.productName,
|
||||
required this.quantity,
|
||||
required this.portion});
|
||||
|
||||
Portion.fromJson(v);
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['id'] = this.id;
|
||||
data['product_name'] = this.productName;
|
||||
data['quantity'] = this.quantity;
|
||||
data['portion'] = this.portion;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
class Photo {
|
||||
late int id;
|
||||
late String originalName;
|
||||
late String path;
|
||||
late int size;
|
||||
|
||||
Photo(
|
||||
{required this.id,
|
||||
required this.originalName,
|
||||
required this.path,
|
||||
required this.size});
|
||||
|
||||
Photo.fromJson(Map<String, dynamic> json) {
|
||||
id = json['id'];
|
||||
originalName = json['original_name'];
|
||||
path = json['path'];
|
||||
size = json['size'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['id'] = this.id;
|
||||
data['original_name'] = this.originalName;
|
||||
data['path'] = this.path;
|
||||
data['size'] = this.size;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@ DiaryModel _$DiaryModelFromJson(Map<String, dynamic> json) {
|
||||
mixin _$DiaryModel {
|
||||
int get id => throw _privateConstructorUsedError;
|
||||
DateTime get date => throw _privateConstructorUsedError;
|
||||
DateTime get wakeup => throw _privateConstructorUsedError;
|
||||
DateTime get retire => throw _privateConstructorUsedError;
|
||||
int get closed => throw _privateConstructorUsedError;
|
||||
String get comment => throw _privateConstructorUsedError;
|
||||
List<Meal> get meals => throw _privateConstructorUsedError;
|
||||
List<Meal>? get meals => throw _privateConstructorUsedError;
|
||||
String? get comment => throw _privateConstructorUsedError;
|
||||
DateTime? get wakeup => throw _privateConstructorUsedError;
|
||||
DateTime? get retire => throw _privateConstructorUsedError;
|
||||
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
@JsonKey(ignore: true)
|
||||
@@ -43,11 +43,11 @@ abstract class $DiaryModelCopyWith<$Res> {
|
||||
$Res call(
|
||||
{int id,
|
||||
DateTime date,
|
||||
DateTime wakeup,
|
||||
DateTime retire,
|
||||
int closed,
|
||||
String comment,
|
||||
List<Meal> meals});
|
||||
List<Meal>? meals,
|
||||
String? comment,
|
||||
DateTime? wakeup,
|
||||
DateTime? retire});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -65,11 +65,11 @@ class _$DiaryModelCopyWithImpl<$Res, $Val extends DiaryModel>
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? date = null,
|
||||
Object? wakeup = null,
|
||||
Object? retire = null,
|
||||
Object? closed = null,
|
||||
Object? comment = null,
|
||||
Object? meals = null,
|
||||
Object? meals = freezed,
|
||||
Object? comment = freezed,
|
||||
Object? wakeup = freezed,
|
||||
Object? retire = freezed,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
id: null == id
|
||||
@@ -80,26 +80,26 @@ class _$DiaryModelCopyWithImpl<$Res, $Val extends DiaryModel>
|
||||
? _value.date
|
||||
: date // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime,
|
||||
wakeup: null == wakeup
|
||||
? _value.wakeup
|
||||
: wakeup // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime,
|
||||
retire: null == retire
|
||||
? _value.retire
|
||||
: retire // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime,
|
||||
closed: null == closed
|
||||
? _value.closed
|
||||
: closed // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
comment: null == comment
|
||||
? _value.comment
|
||||
: comment // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
meals: null == meals
|
||||
meals: freezed == meals
|
||||
? _value.meals
|
||||
: meals // ignore: cast_nullable_to_non_nullable
|
||||
as List<Meal>,
|
||||
as List<Meal>?,
|
||||
comment: freezed == comment
|
||||
? _value.comment
|
||||
: comment // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
wakeup: freezed == wakeup
|
||||
? _value.wakeup
|
||||
: wakeup // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,
|
||||
retire: freezed == retire
|
||||
? _value.retire
|
||||
: retire // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
@@ -115,11 +115,11 @@ abstract class _$$DiaryModelImplCopyWith<$Res>
|
||||
$Res call(
|
||||
{int id,
|
||||
DateTime date,
|
||||
DateTime wakeup,
|
||||
DateTime retire,
|
||||
int closed,
|
||||
String comment,
|
||||
List<Meal> meals});
|
||||
List<Meal>? meals,
|
||||
String? comment,
|
||||
DateTime? wakeup,
|
||||
DateTime? retire});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -135,11 +135,11 @@ class __$$DiaryModelImplCopyWithImpl<$Res>
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? date = null,
|
||||
Object? wakeup = null,
|
||||
Object? retire = null,
|
||||
Object? closed = null,
|
||||
Object? comment = null,
|
||||
Object? meals = null,
|
||||
Object? meals = freezed,
|
||||
Object? comment = freezed,
|
||||
Object? wakeup = freezed,
|
||||
Object? retire = freezed,
|
||||
}) {
|
||||
return _then(_$DiaryModelImpl(
|
||||
id: null == id
|
||||
@@ -150,26 +150,26 @@ class __$$DiaryModelImplCopyWithImpl<$Res>
|
||||
? _value.date
|
||||
: date // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime,
|
||||
wakeup: null == wakeup
|
||||
? _value.wakeup
|
||||
: wakeup // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime,
|
||||
retire: null == retire
|
||||
? _value.retire
|
||||
: retire // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime,
|
||||
closed: null == closed
|
||||
? _value.closed
|
||||
: closed // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
comment: null == comment
|
||||
? _value.comment
|
||||
: comment // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
meals: null == meals
|
||||
meals: freezed == meals
|
||||
? _value._meals
|
||||
: meals // ignore: cast_nullable_to_non_nullable
|
||||
as List<Meal>,
|
||||
as List<Meal>?,
|
||||
comment: freezed == comment
|
||||
? _value.comment
|
||||
: comment // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
wakeup: freezed == wakeup
|
||||
? _value.wakeup
|
||||
: wakeup // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,
|
||||
retire: freezed == retire
|
||||
? _value.retire
|
||||
: retire // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -180,11 +180,11 @@ class _$DiaryModelImpl implements _DiaryModel {
|
||||
const _$DiaryModelImpl(
|
||||
{required this.id,
|
||||
required this.date,
|
||||
required this.wakeup,
|
||||
required this.retire,
|
||||
required this.closed,
|
||||
required this.comment,
|
||||
required final List<Meal> meals})
|
||||
required final List<Meal>? meals,
|
||||
this.comment,
|
||||
this.wakeup,
|
||||
this.retire})
|
||||
: _meals = meals;
|
||||
|
||||
factory _$DiaryModelImpl.fromJson(Map<String, dynamic> json) =>
|
||||
@@ -195,24 +195,27 @@ class _$DiaryModelImpl implements _DiaryModel {
|
||||
@override
|
||||
final DateTime date;
|
||||
@override
|
||||
final DateTime wakeup;
|
||||
@override
|
||||
final DateTime retire;
|
||||
@override
|
||||
final int closed;
|
||||
final List<Meal>? _meals;
|
||||
@override
|
||||
final String comment;
|
||||
final List<Meal> _meals;
|
||||
@override
|
||||
List<Meal> get meals {
|
||||
List<Meal>? get meals {
|
||||
final value = _meals;
|
||||
if (value == null) return null;
|
||||
if (_meals is EqualUnmodifiableListView) return _meals;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_meals);
|
||||
return EqualUnmodifiableListView(value);
|
||||
}
|
||||
|
||||
@override
|
||||
final String? comment;
|
||||
@override
|
||||
final DateTime? wakeup;
|
||||
@override
|
||||
final DateTime? retire;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'DiaryModel(id: $id, date: $date, wakeup: $wakeup, retire: $retire, closed: $closed, comment: $comment, meals: $meals)';
|
||||
return 'DiaryModel(id: $id, date: $date, closed: $closed, meals: $meals, comment: $comment, wakeup: $wakeup, retire: $retire)';
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -222,17 +225,17 @@ class _$DiaryModelImpl implements _DiaryModel {
|
||||
other is _$DiaryModelImpl &&
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.date, date) || other.date == date) &&
|
||||
(identical(other.wakeup, wakeup) || other.wakeup == wakeup) &&
|
||||
(identical(other.retire, retire) || other.retire == retire) &&
|
||||
(identical(other.closed, closed) || other.closed == closed) &&
|
||||
const DeepCollectionEquality().equals(other._meals, _meals) &&
|
||||
(identical(other.comment, comment) || other.comment == comment) &&
|
||||
const DeepCollectionEquality().equals(other._meals, _meals));
|
||||
(identical(other.wakeup, wakeup) || other.wakeup == wakeup) &&
|
||||
(identical(other.retire, retire) || other.retire == retire));
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, id, date, wakeup, retire, closed,
|
||||
comment, const DeepCollectionEquality().hash(_meals));
|
||||
int get hashCode => Object.hash(runtimeType, id, date, closed,
|
||||
const DeepCollectionEquality().hash(_meals), comment, wakeup, retire);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@@ -252,11 +255,11 @@ abstract class _DiaryModel implements DiaryModel {
|
||||
const factory _DiaryModel(
|
||||
{required final int id,
|
||||
required final DateTime date,
|
||||
required final DateTime wakeup,
|
||||
required final DateTime retire,
|
||||
required final int closed,
|
||||
required final String comment,
|
||||
required final List<Meal> meals}) = _$DiaryModelImpl;
|
||||
required final List<Meal>? meals,
|
||||
final String? comment,
|
||||
final DateTime? wakeup,
|
||||
final DateTime? retire}) = _$DiaryModelImpl;
|
||||
|
||||
factory _DiaryModel.fromJson(Map<String, dynamic> json) =
|
||||
_$DiaryModelImpl.fromJson;
|
||||
@@ -266,15 +269,15 @@ abstract class _DiaryModel implements DiaryModel {
|
||||
@override
|
||||
DateTime get date;
|
||||
@override
|
||||
DateTime get wakeup;
|
||||
@override
|
||||
DateTime get retire;
|
||||
@override
|
||||
int get closed;
|
||||
@override
|
||||
String get comment;
|
||||
List<Meal>? get meals;
|
||||
@override
|
||||
List<Meal> get meals;
|
||||
String? get comment;
|
||||
@override
|
||||
DateTime? get wakeup;
|
||||
@override
|
||||
DateTime? get retire;
|
||||
@override
|
||||
@JsonKey(ignore: true)
|
||||
_$$DiaryModelImplCopyWith<_$DiaryModelImpl> get copyWith =>
|
||||
|
||||
@@ -10,22 +10,26 @@ _$DiaryModelImpl _$$DiaryModelImplFromJson(Map<String, dynamic> json) =>
|
||||
_$DiaryModelImpl(
|
||||
id: (json['id'] as num).toInt(),
|
||||
date: DateTime.parse(json['date'] as String),
|
||||
wakeup: DateTime.parse(json['wakeup'] as String),
|
||||
retire: DateTime.parse(json['retire'] as String),
|
||||
closed: (json['closed'] as num).toInt(),
|
||||
comment: json['comment'] as String,
|
||||
meals: (json['meals'] as List<dynamic>)
|
||||
.map((e) => Meal.fromJson(e as Map<String, dynamic>))
|
||||
meals: (json['meals'] as List<dynamic>?)
|
||||
?.map((e) => Meal.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
comment: json['comment'] as String?,
|
||||
wakeup: json['wakeup'] == null
|
||||
? null
|
||||
: DateTime.parse(json['wakeup'] as String),
|
||||
retire: json['retire'] == null
|
||||
? null
|
||||
: DateTime.parse(json['retire'] as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$DiaryModelImplToJson(_$DiaryModelImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'date': instance.date.toIso8601String(),
|
||||
'wakeup': instance.wakeup.toIso8601String(),
|
||||
'retire': instance.retire.toIso8601String(),
|
||||
'closed': instance.closed,
|
||||
'comment': instance.comment,
|
||||
'meals': instance.meals,
|
||||
'comment': instance.comment,
|
||||
'wakeup': instance.wakeup?.toIso8601String(),
|
||||
'retire': instance.retire?.toIso8601String(),
|
||||
};
|
||||
|
||||
21
lib/features/diary/models/meal.dart
Normal file
21
lib/features/diary/models/meal.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import './portion.dart';
|
||||
import './photo.dart';
|
||||
|
||||
part 'meal.freezed.dart';
|
||||
part 'meal.g.dart';
|
||||
|
||||
@freezed
|
||||
class Meal with _$Meal {
|
||||
const factory Meal({
|
||||
required int id,
|
||||
required String time,
|
||||
required int type,
|
||||
required int satiety,
|
||||
required int mood,
|
||||
required List<Portion> portions,
|
||||
required List<Photo> photos,
|
||||
}) = _Meal;
|
||||
|
||||
factory Meal.fromJson(Map<String, Object?> json) => _$MealFromJson(json);
|
||||
}
|
||||
291
lib/features/diary/models/meal.freezed.dart
Normal file
291
lib/features/diary/models/meal.freezed.dart
Normal file
@@ -0,0 +1,291 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'meal.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
|
||||
|
||||
Meal _$MealFromJson(Map<String, dynamic> json) {
|
||||
return _Meal.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$Meal {
|
||||
int get id => throw _privateConstructorUsedError;
|
||||
String get time => throw _privateConstructorUsedError;
|
||||
int get type => throw _privateConstructorUsedError;
|
||||
int get satiety => throw _privateConstructorUsedError;
|
||||
int get mood => throw _privateConstructorUsedError;
|
||||
List<Portion> get portions => throw _privateConstructorUsedError;
|
||||
List<Photo> get photos => throw _privateConstructorUsedError;
|
||||
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
@JsonKey(ignore: true)
|
||||
$MealCopyWith<Meal> get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $MealCopyWith<$Res> {
|
||||
factory $MealCopyWith(Meal value, $Res Function(Meal) then) =
|
||||
_$MealCopyWithImpl<$Res, Meal>;
|
||||
@useResult
|
||||
$Res call(
|
||||
{int id,
|
||||
String time,
|
||||
int type,
|
||||
int satiety,
|
||||
int mood,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$MealCopyWithImpl<$Res, $Val extends Meal>
|
||||
implements $MealCopyWith<$Res> {
|
||||
_$MealCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? time = null,
|
||||
Object? type = null,
|
||||
Object? satiety = null,
|
||||
Object? mood = null,
|
||||
Object? portions = null,
|
||||
Object? photos = null,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
id: null == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
time: null == time
|
||||
? _value.time
|
||||
: time // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
type: null == type
|
||||
? _value.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
satiety: null == satiety
|
||||
? _value.satiety
|
||||
: satiety // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
mood: null == mood
|
||||
? _value.mood
|
||||
: mood // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
portions: null == portions
|
||||
? _value.portions
|
||||
: portions // ignore: cast_nullable_to_non_nullable
|
||||
as List<Portion>,
|
||||
photos: null == photos
|
||||
? _value.photos
|
||||
: photos // ignore: cast_nullable_to_non_nullable
|
||||
as List<Photo>,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$MealImplCopyWith<$Res> implements $MealCopyWith<$Res> {
|
||||
factory _$$MealImplCopyWith(
|
||||
_$MealImpl value, $Res Function(_$MealImpl) then) =
|
||||
__$$MealImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call(
|
||||
{int id,
|
||||
String time,
|
||||
int type,
|
||||
int satiety,
|
||||
int mood,
|
||||
List<Portion> portions,
|
||||
List<Photo> photos});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$MealImplCopyWithImpl<$Res>
|
||||
extends _$MealCopyWithImpl<$Res, _$MealImpl>
|
||||
implements _$$MealImplCopyWith<$Res> {
|
||||
__$$MealImplCopyWithImpl(_$MealImpl _value, $Res Function(_$MealImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? time = null,
|
||||
Object? type = null,
|
||||
Object? satiety = null,
|
||||
Object? mood = null,
|
||||
Object? portions = null,
|
||||
Object? photos = null,
|
||||
}) {
|
||||
return _then(_$MealImpl(
|
||||
id: null == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
time: null == time
|
||||
? _value.time
|
||||
: time // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
type: null == type
|
||||
? _value.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
satiety: null == satiety
|
||||
? _value.satiety
|
||||
: satiety // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
mood: null == mood
|
||||
? _value.mood
|
||||
: mood // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
portions: null == portions
|
||||
? _value._portions
|
||||
: portions // ignore: cast_nullable_to_non_nullable
|
||||
as List<Portion>,
|
||||
photos: null == photos
|
||||
? _value._photos
|
||||
: photos // ignore: cast_nullable_to_non_nullable
|
||||
as List<Photo>,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$MealImpl implements _Meal {
|
||||
const _$MealImpl(
|
||||
{required this.id,
|
||||
required this.time,
|
||||
required this.type,
|
||||
required this.satiety,
|
||||
required this.mood,
|
||||
required final List<Portion> portions,
|
||||
required final List<Photo> photos})
|
||||
: _portions = portions,
|
||||
_photos = photos;
|
||||
|
||||
factory _$MealImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$MealImplFromJson(json);
|
||||
|
||||
@override
|
||||
final int id;
|
||||
@override
|
||||
final String time;
|
||||
@override
|
||||
final int type;
|
||||
@override
|
||||
final int satiety;
|
||||
@override
|
||||
final int mood;
|
||||
final List<Portion> _portions;
|
||||
@override
|
||||
List<Portion> get portions {
|
||||
if (_portions is EqualUnmodifiableListView) return _portions;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_portions);
|
||||
}
|
||||
|
||||
final List<Photo> _photos;
|
||||
@override
|
||||
List<Photo> get photos {
|
||||
if (_photos is EqualUnmodifiableListView) return _photos;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_photos);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Meal(id: $id, time: $time, type: $type, satiety: $satiety, mood: $mood, portions: $portions, photos: $photos)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$MealImpl &&
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.time, time) || other.time == time) &&
|
||||
(identical(other.type, type) || other.type == type) &&
|
||||
(identical(other.satiety, satiety) || other.satiety == satiety) &&
|
||||
(identical(other.mood, mood) || other.mood == mood) &&
|
||||
const DeepCollectionEquality().equals(other._portions, _portions) &&
|
||||
const DeepCollectionEquality().equals(other._photos, _photos));
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
id,
|
||||
time,
|
||||
type,
|
||||
satiety,
|
||||
mood,
|
||||
const DeepCollectionEquality().hash(_portions),
|
||||
const DeepCollectionEquality().hash(_photos));
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$MealImplCopyWith<_$MealImpl> get copyWith =>
|
||||
__$$MealImplCopyWithImpl<_$MealImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$MealImplToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _Meal implements Meal {
|
||||
const factory _Meal(
|
||||
{required final int id,
|
||||
required final String time,
|
||||
required final int type,
|
||||
required final int satiety,
|
||||
required final int mood,
|
||||
required final List<Portion> portions,
|
||||
required final List<Photo> photos}) = _$MealImpl;
|
||||
|
||||
factory _Meal.fromJson(Map<String, dynamic> json) = _$MealImpl.fromJson;
|
||||
|
||||
@override
|
||||
int get id;
|
||||
@override
|
||||
String get time;
|
||||
@override
|
||||
int get type;
|
||||
@override
|
||||
int get satiety;
|
||||
@override
|
||||
int get mood;
|
||||
@override
|
||||
List<Portion> get portions;
|
||||
@override
|
||||
List<Photo> get photos;
|
||||
@override
|
||||
@JsonKey(ignore: true)
|
||||
_$$MealImplCopyWith<_$MealImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
32
lib/features/diary/models/meal.g.dart
Normal file
32
lib/features/diary/models/meal.g.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'meal.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$MealImpl _$$MealImplFromJson(Map<String, dynamic> json) => _$MealImpl(
|
||||
id: (json['id'] as num).toInt(),
|
||||
time: json['time'] as String,
|
||||
type: (json['type'] as num).toInt(),
|
||||
satiety: (json['satiety'] as num).toInt(),
|
||||
mood: (json['mood'] as num).toInt(),
|
||||
portions: (json['portions'] as List<dynamic>)
|
||||
.map((e) => Portion.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
photos: (json['photos'] as List<dynamic>)
|
||||
.map((e) => Photo.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$MealImplToJson(_$MealImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'time': instance.time,
|
||||
'type': instance.type,
|
||||
'satiety': instance.satiety,
|
||||
'mood': instance.mood,
|
||||
'portions': instance.portions,
|
||||
'photos': instance.photos,
|
||||
};
|
||||
16
lib/features/diary/models/photo.dart
Normal file
16
lib/features/diary/models/photo.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'photo.freezed.dart';
|
||||
part 'photo.g.dart';
|
||||
|
||||
@freezed
|
||||
class Photo with _$Photo {
|
||||
const factory Photo({
|
||||
required int id,
|
||||
required String originalName,
|
||||
required String path,
|
||||
required int size,
|
||||
}) = _Photo;
|
||||
|
||||
factory Photo.fromJson(Map<String, Object?> json) => _$PhotoFromJson(json);
|
||||
}
|
||||
204
lib/features/diary/models/photo.freezed.dart
Normal file
204
lib/features/diary/models/photo.freezed.dart
Normal file
@@ -0,0 +1,204 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'photo.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
|
||||
|
||||
Photo _$PhotoFromJson(Map<String, dynamic> json) {
|
||||
return _Photo.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$Photo {
|
||||
int get id => throw _privateConstructorUsedError;
|
||||
String get originalName => throw _privateConstructorUsedError;
|
||||
String get path => throw _privateConstructorUsedError;
|
||||
int get size => throw _privateConstructorUsedError;
|
||||
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
@JsonKey(ignore: true)
|
||||
$PhotoCopyWith<Photo> get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $PhotoCopyWith<$Res> {
|
||||
factory $PhotoCopyWith(Photo value, $Res Function(Photo) then) =
|
||||
_$PhotoCopyWithImpl<$Res, Photo>;
|
||||
@useResult
|
||||
$Res call({int id, String originalName, String path, int size});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$PhotoCopyWithImpl<$Res, $Val extends Photo>
|
||||
implements $PhotoCopyWith<$Res> {
|
||||
_$PhotoCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? originalName = null,
|
||||
Object? path = null,
|
||||
Object? size = null,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
id: null == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
originalName: null == originalName
|
||||
? _value.originalName
|
||||
: originalName // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
path: null == path
|
||||
? _value.path
|
||||
: path // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
size: null == size
|
||||
? _value.size
|
||||
: size // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$PhotoImplCopyWith<$Res> implements $PhotoCopyWith<$Res> {
|
||||
factory _$$PhotoImplCopyWith(
|
||||
_$PhotoImpl value, $Res Function(_$PhotoImpl) then) =
|
||||
__$$PhotoImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({int id, String originalName, String path, int size});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$PhotoImplCopyWithImpl<$Res>
|
||||
extends _$PhotoCopyWithImpl<$Res, _$PhotoImpl>
|
||||
implements _$$PhotoImplCopyWith<$Res> {
|
||||
__$$PhotoImplCopyWithImpl(
|
||||
_$PhotoImpl _value, $Res Function(_$PhotoImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? originalName = null,
|
||||
Object? path = null,
|
||||
Object? size = null,
|
||||
}) {
|
||||
return _then(_$PhotoImpl(
|
||||
id: null == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
originalName: null == originalName
|
||||
? _value.originalName
|
||||
: originalName // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
path: null == path
|
||||
? _value.path
|
||||
: path // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
size: null == size
|
||||
? _value.size
|
||||
: size // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$PhotoImpl implements _Photo {
|
||||
const _$PhotoImpl(
|
||||
{required this.id,
|
||||
required this.originalName,
|
||||
required this.path,
|
||||
required this.size});
|
||||
|
||||
factory _$PhotoImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$PhotoImplFromJson(json);
|
||||
|
||||
@override
|
||||
final int id;
|
||||
@override
|
||||
final String originalName;
|
||||
@override
|
||||
final String path;
|
||||
@override
|
||||
final int size;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Photo(id: $id, originalName: $originalName, path: $path, size: $size)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$PhotoImpl &&
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.originalName, originalName) ||
|
||||
other.originalName == originalName) &&
|
||||
(identical(other.path, path) || other.path == path) &&
|
||||
(identical(other.size, size) || other.size == size));
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, id, originalName, path, size);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$PhotoImplCopyWith<_$PhotoImpl> get copyWith =>
|
||||
__$$PhotoImplCopyWithImpl<_$PhotoImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$PhotoImplToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _Photo implements Photo {
|
||||
const factory _Photo(
|
||||
{required final int id,
|
||||
required final String originalName,
|
||||
required final String path,
|
||||
required final int size}) = _$PhotoImpl;
|
||||
|
||||
factory _Photo.fromJson(Map<String, dynamic> json) = _$PhotoImpl.fromJson;
|
||||
|
||||
@override
|
||||
int get id;
|
||||
@override
|
||||
String get originalName;
|
||||
@override
|
||||
String get path;
|
||||
@override
|
||||
int get size;
|
||||
@override
|
||||
@JsonKey(ignore: true)
|
||||
_$$PhotoImplCopyWith<_$PhotoImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
22
lib/features/diary/models/photo.g.dart
Normal file
22
lib/features/diary/models/photo.g.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'photo.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$PhotoImpl _$$PhotoImplFromJson(Map<String, dynamic> json) => _$PhotoImpl(
|
||||
id: (json['id'] as num).toInt(),
|
||||
originalName: json['originalName'] as String,
|
||||
path: json['path'] as String,
|
||||
size: (json['size'] as num).toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$PhotoImplToJson(_$PhotoImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'originalName': instance.originalName,
|
||||
'path': instance.path,
|
||||
'size': instance.size,
|
||||
};
|
||||
17
lib/features/diary/models/portion.dart
Normal file
17
lib/features/diary/models/portion.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'portion.freezed.dart';
|
||||
part 'portion.g.dart';
|
||||
|
||||
@freezed
|
||||
class Portion with _$Portion {
|
||||
const factory Portion({
|
||||
required int id,
|
||||
required String productName,
|
||||
required int quantity,
|
||||
required String portion,
|
||||
}) = _Portion;
|
||||
|
||||
factory Portion.fromJson(Map<String, Object?> json) =>
|
||||
_$PortionFromJson(json);
|
||||
}
|
||||
206
lib/features/diary/models/portion.freezed.dart
Normal file
206
lib/features/diary/models/portion.freezed.dart
Normal file
@@ -0,0 +1,206 @@
|
||||
// coverage:ignore-file
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'portion.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
final _privateConstructorUsedError = UnsupportedError(
|
||||
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
|
||||
|
||||
Portion _$PortionFromJson(Map<String, dynamic> json) {
|
||||
return _Portion.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$Portion {
|
||||
int get id => throw _privateConstructorUsedError;
|
||||
String get productName => throw _privateConstructorUsedError;
|
||||
int get quantity => throw _privateConstructorUsedError;
|
||||
String get portion => throw _privateConstructorUsedError;
|
||||
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
@JsonKey(ignore: true)
|
||||
$PortionCopyWith<Portion> get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $PortionCopyWith<$Res> {
|
||||
factory $PortionCopyWith(Portion value, $Res Function(Portion) then) =
|
||||
_$PortionCopyWithImpl<$Res, Portion>;
|
||||
@useResult
|
||||
$Res call({int id, String productName, int quantity, String portion});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$PortionCopyWithImpl<$Res, $Val extends Portion>
|
||||
implements $PortionCopyWith<$Res> {
|
||||
_$PortionCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? productName = null,
|
||||
Object? quantity = null,
|
||||
Object? portion = null,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
id: null == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
productName: null == productName
|
||||
? _value.productName
|
||||
: productName // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
quantity: null == quantity
|
||||
? _value.quantity
|
||||
: quantity // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
portion: null == portion
|
||||
? _value.portion
|
||||
: portion // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$PortionImplCopyWith<$Res> implements $PortionCopyWith<$Res> {
|
||||
factory _$$PortionImplCopyWith(
|
||||
_$PortionImpl value, $Res Function(_$PortionImpl) then) =
|
||||
__$$PortionImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({int id, String productName, int quantity, String portion});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$PortionImplCopyWithImpl<$Res>
|
||||
extends _$PortionCopyWithImpl<$Res, _$PortionImpl>
|
||||
implements _$$PortionImplCopyWith<$Res> {
|
||||
__$$PortionImplCopyWithImpl(
|
||||
_$PortionImpl _value, $Res Function(_$PortionImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? productName = null,
|
||||
Object? quantity = null,
|
||||
Object? portion = null,
|
||||
}) {
|
||||
return _then(_$PortionImpl(
|
||||
id: null == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
productName: null == productName
|
||||
? _value.productName
|
||||
: productName // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
quantity: null == quantity
|
||||
? _value.quantity
|
||||
: quantity // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
portion: null == portion
|
||||
? _value.portion
|
||||
: portion // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$PortionImpl implements _Portion {
|
||||
const _$PortionImpl(
|
||||
{required this.id,
|
||||
required this.productName,
|
||||
required this.quantity,
|
||||
required this.portion});
|
||||
|
||||
factory _$PortionImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$PortionImplFromJson(json);
|
||||
|
||||
@override
|
||||
final int id;
|
||||
@override
|
||||
final String productName;
|
||||
@override
|
||||
final int quantity;
|
||||
@override
|
||||
final String portion;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Portion(id: $id, productName: $productName, quantity: $quantity, portion: $portion)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$PortionImpl &&
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.productName, productName) ||
|
||||
other.productName == productName) &&
|
||||
(identical(other.quantity, quantity) ||
|
||||
other.quantity == quantity) &&
|
||||
(identical(other.portion, portion) || other.portion == portion));
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode =>
|
||||
Object.hash(runtimeType, id, productName, quantity, portion);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$PortionImplCopyWith<_$PortionImpl> get copyWith =>
|
||||
__$$PortionImplCopyWithImpl<_$PortionImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$PortionImplToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _Portion implements Portion {
|
||||
const factory _Portion(
|
||||
{required final int id,
|
||||
required final String productName,
|
||||
required final int quantity,
|
||||
required final String portion}) = _$PortionImpl;
|
||||
|
||||
factory _Portion.fromJson(Map<String, dynamic> json) = _$PortionImpl.fromJson;
|
||||
|
||||
@override
|
||||
int get id;
|
||||
@override
|
||||
String get productName;
|
||||
@override
|
||||
int get quantity;
|
||||
@override
|
||||
String get portion;
|
||||
@override
|
||||
@JsonKey(ignore: true)
|
||||
_$$PortionImplCopyWith<_$PortionImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
23
lib/features/diary/models/portion.g.dart
Normal file
23
lib/features/diary/models/portion.g.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'portion.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$PortionImpl _$$PortionImplFromJson(Map<String, dynamic> json) =>
|
||||
_$PortionImpl(
|
||||
id: (json['id'] as num).toInt(),
|
||||
productName: json['productName'] as String,
|
||||
quantity: (json['quantity'] as num).toInt(),
|
||||
portion: json['portion'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$PortionImplToJson(_$PortionImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'productName': instance.productName,
|
||||
'quantity': instance.quantity,
|
||||
'portion': instance.portion,
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'package:eatvio_app/features/diary/models/diary_model.dart';
|
||||
import 'package:eatvio_app/features/diary/models/meal.dart';
|
||||
import 'package:eatvio_app/features/diary/repositories/diary_repository.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
@@ -53,10 +53,10 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
) async {
|
||||
emit(const DiaryState.loading());
|
||||
try {
|
||||
final diary =
|
||||
await diaryRepository.getDiary(await diaryRepository.getDiaryID());
|
||||
Map<String, int> data = await diaryRepository.getDiaryID();
|
||||
final int? diaryID = data['id'];
|
||||
emit(DiaryState.loaded(
|
||||
diary: diary,
|
||||
diary: await diaryRepository.getDiary(diaryID ?? 45),
|
||||
commentController: TextEditingController(),
|
||||
productNameController: TextEditingController(),
|
||||
productQuantityController: TextEditingController(),
|
||||
@@ -359,8 +359,8 @@ class DiaryBloc extends Bloc<DiaryEvent, DiaryState> {
|
||||
) async {
|
||||
if (state is DiaryStateLoaded) {
|
||||
var currentState = state as DiaryStateLoaded;
|
||||
Meal? meal =
|
||||
currentState.diary.meals.firstWhere((meal) => meal.id == event.value);
|
||||
Meal? meal = currentState.diary.meals!
|
||||
.firstWhere((meal) => meal.id == event.value);
|
||||
|
||||
DiaryStateLoaded updatedState = currentState.copyWith(
|
||||
currentMeal: event.value,
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import 'package:eatvio_app/features/diary/models/diary_model.dart';
|
||||
import 'package:eatvio_app/features/diary/models/meal.dart';
|
||||
import 'package:eatvio_app/features/diary/models/photo.dart';
|
||||
import 'package:eatvio_app/features/diary/models/portion.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
|
||||
@@ -592,6 +592,7 @@ abstract class _$$DiaryStateLoadedImplCopyWith<$Res> {
|
||||
bool isAdded});
|
||||
|
||||
$DiaryModelCopyWith<$Res> get diary;
|
||||
$MealCopyWith<$Res>? get currentMeal;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -747,6 +748,18 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res>
|
||||
return _then(_value.copyWith(diary: value));
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$MealCopyWith<$Res>? get currentMeal {
|
||||
if (_value.currentMeal == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $MealCopyWith<$Res>(_value.currentMeal!, (value) {
|
||||
return _then(_value.copyWith(currentMeal: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
// ignore_for_file: unused_local_variable
|
||||
|
||||
import 'package:eatvio_app/features/diary/models/diary_model.dart';
|
||||
import 'package:eatvio_app/features/diary/models/meal.dart';
|
||||
import 'package:eatvio_app/features/diary/models/photo.dart';
|
||||
import 'package:eatvio_app/features/diary/models/portion.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_bloc.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
|
||||
import 'package:eatvio_app/locator_service.dart';
|
||||
@@ -674,12 +677,12 @@ class DiaryScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
_buildCarousel(BuildContext context, DiaryStateLoaded state) {
|
||||
if (state.currentMeal!.photos!.isEmpty) {
|
||||
if (state.currentMeal!.photos.isEmpty) {
|
||||
return Text("Фото нет");
|
||||
} else {
|
||||
return CarouselSlider(
|
||||
options: CarouselOptions(height: 340.0),
|
||||
items: state.currentMeal!.photos!.map<Widget>((photo) {
|
||||
items: state.currentMeal!.photos.map<Widget>((photo) {
|
||||
return _buildPhoto(
|
||||
context, photo); // Assuming photos are stored as strings
|
||||
}).toList(),
|
||||
@@ -1311,8 +1314,8 @@ bool checkConsumedValues(
|
||||
return false; // Возвращаем true
|
||||
}
|
||||
|
||||
List<SelectionPopupModel> mealsToDropdown(List<Meal> meals) {
|
||||
return meals
|
||||
List<SelectionPopupModel> mealsToDropdown(List<Meal>? meals) {
|
||||
return meals!
|
||||
.map((meal) => SelectionPopupModel(
|
||||
id: meal.id,
|
||||
title: "Прием пищи ${meal.id}",
|
||||
|
||||
@@ -6,7 +6,7 @@ class DiaryRepository {
|
||||
|
||||
DiaryRepository({required this.diaryService});
|
||||
|
||||
Future<int> getDiaryID() async {
|
||||
Future<Map<String, int>> getDiaryID() async {
|
||||
try {
|
||||
return await diaryService.getDiaryID();
|
||||
} catch (e) {
|
||||
|
||||
@@ -10,7 +10,7 @@ abstract class DiaryService {
|
||||
factory DiaryService(Dio dio, {String baseUrl}) = _DiaryService;
|
||||
|
||||
@GET('/diary/index')
|
||||
Future<int> getDiaryID();
|
||||
Future<Map<String, int>> getDiaryID();
|
||||
|
||||
@GET('/diary/{id}/show/')
|
||||
Future<DiaryModel> getDiary(@Path() int id);
|
||||
|
||||
@@ -19,28 +19,29 @@ class _DiaryService implements DiaryService {
|
||||
String? baseUrl;
|
||||
|
||||
@override
|
||||
Future<int> getDiaryID() async {
|
||||
Future<Map<String, int>> getDiaryID() async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _result = await _dio.fetch<int>(_setStreamType<int>(Options(
|
||||
final _result = await _dio
|
||||
.fetch<Map<String, dynamic>>(_setStreamType<Map<String, int>>(Options(
|
||||
method: 'GET',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/diary/index',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
final _value = _result.data!;
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/diary/index',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
final _value = _result.data!.cast<String, int>();
|
||||
return _value;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:eatvio_app/presentation/diary/diary_edit_screen/diary_edit_screen.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_bloc.dart';
|
||||
import 'package:eatvio_app/presentation/diary/diary_edit_screen/models/diary_edit_model.dart';
|
||||
|
||||
void main() {
|
||||
group('DiaryEditScreen', () {
|
||||
/*testWidgets('renders CircularProgressIndicator when in initial state',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: DiaryEditScreen(),
|
||||
),
|
||||
);
|
||||
});*/
|
||||
|
||||
testWidgets('renders _buildDiaryEditScreen when in loaded state', (WidgetTester tester) async {
|
||||
final diaryEditBloc = DiaryEditBloc(DiaryEditState(diaryEditModelObj: DiaryEditModel()));
|
||||
final loadedState = DiaryEditLoadedState(
|
||||
diaryId: 1,
|
||||
selectedSatiety: 4,
|
||||
autocompleteList: [],
|
||||
photos: [],
|
||||
portions: [],
|
||||
wakeupExpanded: false,
|
||||
moderationExpanded: false,
|
||||
recommendedChartValues: [10, 10, 10, 10],
|
||||
consumedChartValues: [1, 2, 3, 4],
|
||||
moodExpanded: false,);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: BlocProvider<DiaryEditBloc>.value(
|
||||
value: diaryEditBloc,
|
||||
child: DiaryEditScreen(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
diaryEditBloc.emit(loadedState);
|
||||
await tester.pump();
|
||||
|
||||
//expect(find.byType(_buildDiaryEditScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
/*testWidgets('renders error message when in error state',
|
||||
(WidgetTester tester) async {
|
||||
final diaryEditBloc =
|
||||
DiaryEditBloc(DiaryEditState(diaryEditModelObj: DiaryEditModel()));
|
||||
final errorState = DiaryEditErrorState("error");
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: BlocProvider<DiaryEditBloc>.value(
|
||||
value: diaryEditBloc,
|
||||
child: DiaryEditScreen(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
diaryEditBloc.emit(errorState);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Ошибка'), findsOneWidget);
|
||||
});*/
|
||||
|
||||
// Add more tests for other scenarios if needed
|
||||
});
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user