feat(diary): Checkboxes for product when diet is chosen

This commit is contained in:
2024-08-16 16:26:22 +03:00
parent 684b2eec9d
commit 9497789eb5
11 changed files with 369 additions and 63 deletions

View File

@@ -1,3 +1,4 @@
import 'package:eatvio_app/features/diary/models/state.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import './meal.dart';
@@ -12,6 +13,7 @@ class DiaryModel with _$DiaryModel {
required DateTime date,
required int closed,
required List<Meal> meals,
required State state,
String? comment,
DateTime? wakeup,
DateTime? retire,

View File

@@ -24,6 +24,7 @@ mixin _$DiaryModel {
DateTime get date => throw _privateConstructorUsedError;
int get closed => throw _privateConstructorUsedError;
List<Meal> get meals => throw _privateConstructorUsedError;
State get state => throw _privateConstructorUsedError;
String? get comment => throw _privateConstructorUsedError;
DateTime? get wakeup => throw _privateConstructorUsedError;
DateTime? get retire => throw _privateConstructorUsedError;
@@ -45,9 +46,12 @@ abstract class $DiaryModelCopyWith<$Res> {
DateTime date,
int closed,
List<Meal> meals,
State state,
String? comment,
DateTime? wakeup,
DateTime? retire});
$StateCopyWith<$Res> get state;
}
/// @nodoc
@@ -67,6 +71,7 @@ class _$DiaryModelCopyWithImpl<$Res, $Val extends DiaryModel>
Object? date = null,
Object? closed = null,
Object? meals = null,
Object? state = null,
Object? comment = freezed,
Object? wakeup = freezed,
Object? retire = freezed,
@@ -88,6 +93,10 @@ class _$DiaryModelCopyWithImpl<$Res, $Val extends DiaryModel>
? _value.meals
: meals // ignore: cast_nullable_to_non_nullable
as List<Meal>,
state: null == state
? _value.state
: state // ignore: cast_nullable_to_non_nullable
as State,
comment: freezed == comment
? _value.comment
: comment // ignore: cast_nullable_to_non_nullable
@@ -102,6 +111,14 @@ class _$DiaryModelCopyWithImpl<$Res, $Val extends DiaryModel>
as DateTime?,
) as $Val);
}
@override
@pragma('vm:prefer-inline')
$StateCopyWith<$Res> get state {
return $StateCopyWith<$Res>(_value.state, (value) {
return _then(_value.copyWith(state: value) as $Val);
});
}
}
/// @nodoc
@@ -117,9 +134,13 @@ abstract class _$$DiaryModelImplCopyWith<$Res>
DateTime date,
int closed,
List<Meal> meals,
State state,
String? comment,
DateTime? wakeup,
DateTime? retire});
@override
$StateCopyWith<$Res> get state;
}
/// @nodoc
@@ -137,6 +158,7 @@ class __$$DiaryModelImplCopyWithImpl<$Res>
Object? date = null,
Object? closed = null,
Object? meals = null,
Object? state = null,
Object? comment = freezed,
Object? wakeup = freezed,
Object? retire = freezed,
@@ -158,6 +180,10 @@ class __$$DiaryModelImplCopyWithImpl<$Res>
? _value._meals
: meals // ignore: cast_nullable_to_non_nullable
as List<Meal>,
state: null == state
? _value.state
: state // ignore: cast_nullable_to_non_nullable
as State,
comment: freezed == comment
? _value.comment
: comment // ignore: cast_nullable_to_non_nullable
@@ -182,6 +208,7 @@ class _$DiaryModelImpl implements _DiaryModel {
required this.date,
required this.closed,
required final List<Meal> meals,
required this.state,
this.comment,
this.wakeup,
this.retire})
@@ -204,6 +231,8 @@ class _$DiaryModelImpl implements _DiaryModel {
return EqualUnmodifiableListView(_meals);
}
@override
final State state;
@override
final String? comment;
@override
@@ -213,7 +242,7 @@ class _$DiaryModelImpl implements _DiaryModel {
@override
String toString() {
return 'DiaryModel(id: $id, date: $date, closed: $closed, meals: $meals, comment: $comment, wakeup: $wakeup, retire: $retire)';
return 'DiaryModel(id: $id, date: $date, closed: $closed, meals: $meals, state: $state, comment: $comment, wakeup: $wakeup, retire: $retire)';
}
@override
@@ -225,6 +254,7 @@ class _$DiaryModelImpl implements _DiaryModel {
(identical(other.date, date) || other.date == date) &&
(identical(other.closed, closed) || other.closed == closed) &&
const DeepCollectionEquality().equals(other._meals, _meals) &&
(identical(other.state, state) || other.state == state) &&
(identical(other.comment, comment) || other.comment == comment) &&
(identical(other.wakeup, wakeup) || other.wakeup == wakeup) &&
(identical(other.retire, retire) || other.retire == retire));
@@ -232,8 +262,16 @@ class _$DiaryModelImpl implements _DiaryModel {
@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, id, date, closed,
const DeepCollectionEquality().hash(_meals), comment, wakeup, retire);
int get hashCode => Object.hash(
runtimeType,
id,
date,
closed,
const DeepCollectionEquality().hash(_meals),
state,
comment,
wakeup,
retire);
@JsonKey(ignore: true)
@override
@@ -255,6 +293,7 @@ abstract class _DiaryModel implements DiaryModel {
required final DateTime date,
required final int closed,
required final List<Meal> meals,
required final State state,
final String? comment,
final DateTime? wakeup,
final DateTime? retire}) = _$DiaryModelImpl;
@@ -271,6 +310,8 @@ abstract class _DiaryModel implements DiaryModel {
@override
List<Meal> get meals;
@override
State get state;
@override
String? get comment;
@override
DateTime? get wakeup;

View File

@@ -14,6 +14,7 @@ _$DiaryModelImpl _$$DiaryModelImplFromJson(Map<String, dynamic> json) =>
meals: (json['meals'] as List<dynamic>)
.map((e) => Meal.fromJson(e as Map<String, dynamic>))
.toList(),
state: State.fromJson(json['state'] as Map<String, dynamic>),
comment: json['comment'] as String?,
wakeup: json['wakeup'] == null
? null
@@ -29,6 +30,7 @@ Map<String, dynamic> _$$DiaryModelImplToJson(_$DiaryModelImpl instance) =>
'date': instance.date.toIso8601String(),
'closed': instance.closed,
'meals': instance.meals,
'state': instance.state,
'comment': instance.comment,
'wakeup': instance.wakeup?.toIso8601String(),
'retire': instance.retire?.toIso8601String(),

View File

@@ -1,3 +1,4 @@
import 'package:eatvio_app/features/diary/models/state.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'portion.freezed.dart';
@@ -10,6 +11,7 @@ class Portion with _$Portion {
required String product_name,
required int quantity,
required String portion,
required bool from_diet,
}) = _Portion;
factory Portion.fromJson(Map<String, Object?> json) => _$PortionFromJson(json);

View File

@@ -24,6 +24,7 @@ mixin _$Portion {
String get product_name => throw _privateConstructorUsedError;
int get quantity => throw _privateConstructorUsedError;
String get portion => throw _privateConstructorUsedError;
bool get from_diet => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
@@ -35,7 +36,12 @@ abstract class $PortionCopyWith<$Res> {
factory $PortionCopyWith(Portion value, $Res Function(Portion) then) =
_$PortionCopyWithImpl<$Res, Portion>;
@useResult
$Res call({int id, String product_name, int quantity, String portion});
$Res call(
{int id,
String product_name,
int quantity,
String portion,
bool from_diet});
}
/// @nodoc
@@ -55,6 +61,7 @@ class _$PortionCopyWithImpl<$Res, $Val extends Portion>
Object? product_name = null,
Object? quantity = null,
Object? portion = null,
Object? from_diet = null,
}) {
return _then(_value.copyWith(
id: null == id
@@ -73,6 +80,10 @@ class _$PortionCopyWithImpl<$Res, $Val extends Portion>
? _value.portion
: portion // ignore: cast_nullable_to_non_nullable
as String,
from_diet: null == from_diet
? _value.from_diet
: from_diet // ignore: cast_nullable_to_non_nullable
as bool,
) as $Val);
}
}
@@ -84,7 +95,12 @@ abstract class _$$PortionImplCopyWith<$Res> implements $PortionCopyWith<$Res> {
__$$PortionImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({int id, String product_name, int quantity, String portion});
$Res call(
{int id,
String product_name,
int quantity,
String portion,
bool from_diet});
}
/// @nodoc
@@ -102,6 +118,7 @@ class __$$PortionImplCopyWithImpl<$Res>
Object? product_name = null,
Object? quantity = null,
Object? portion = null,
Object? from_diet = null,
}) {
return _then(_$PortionImpl(
id: null == id
@@ -120,6 +137,10 @@ class __$$PortionImplCopyWithImpl<$Res>
? _value.portion
: portion // ignore: cast_nullable_to_non_nullable
as String,
from_diet: null == from_diet
? _value.from_diet
: from_diet // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
@@ -131,7 +152,8 @@ class _$PortionImpl implements _Portion {
{required this.id,
required this.product_name,
required this.quantity,
required this.portion});
required this.portion,
required this.from_diet});
factory _$PortionImpl.fromJson(Map<String, dynamic> json) =>
_$$PortionImplFromJson(json);
@@ -144,10 +166,12 @@ class _$PortionImpl implements _Portion {
final int quantity;
@override
final String portion;
@override
final bool from_diet;
@override
String toString() {
return 'Portion(id: $id, product_name: $product_name, quantity: $quantity, portion: $portion)';
return 'Portion(id: $id, product_name: $product_name, quantity: $quantity, portion: $portion, from_diet: $from_diet)';
}
@override
@@ -160,13 +184,15 @@ class _$PortionImpl implements _Portion {
other.product_name == product_name) &&
(identical(other.quantity, quantity) ||
other.quantity == quantity) &&
(identical(other.portion, portion) || other.portion == portion));
(identical(other.portion, portion) || other.portion == portion) &&
(identical(other.from_diet, from_diet) ||
other.from_diet == from_diet));
}
@JsonKey(ignore: true)
@override
int get hashCode =>
Object.hash(runtimeType, id, product_name, quantity, portion);
Object.hash(runtimeType, id, product_name, quantity, portion, from_diet);
@JsonKey(ignore: true)
@override
@@ -187,7 +213,8 @@ abstract class _Portion implements Portion {
{required final int id,
required final String product_name,
required final int quantity,
required final String portion}) = _$PortionImpl;
required final String portion,
required final bool from_diet}) = _$PortionImpl;
factory _Portion.fromJson(Map<String, dynamic> json) = _$PortionImpl.fromJson;
@@ -200,6 +227,8 @@ abstract class _Portion implements Portion {
@override
String get portion;
@override
bool get from_diet;
@override
@JsonKey(ignore: true)
_$$PortionImplCopyWith<_$PortionImpl> get copyWith =>
throw _privateConstructorUsedError;

View File

@@ -12,6 +12,7 @@ _$PortionImpl _$$PortionImplFromJson(Map<String, dynamic> json) =>
product_name: json['product_name'] as String,
quantity: (json['quantity'] as num).toInt(),
portion: json['portion'] as String,
from_diet: json['from_diet'] as bool,
);
Map<String, dynamic> _$$PortionImplToJson(_$PortionImpl instance) =>
@@ -20,4 +21,5 @@ Map<String, dynamic> _$$PortionImplToJson(_$PortionImpl instance) =>
'product_name': instance.product_name,
'quantity': instance.quantity,
'portion': instance.portion,
'from_diet': instance.from_diet,
};

View File

@@ -0,0 +1,14 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'state.freezed.dart';
part 'state.g.dart';
@freezed
class State with _$State {
const factory State({
required bool has_chosen_diet,
required bool has_chosen_plan,
}) = _State;
factory State.fromJson(Map<String, Object?> json) => _$StateFromJson(json);
}

View File

@@ -0,0 +1,169 @@
// 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 'state.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');
State _$StateFromJson(Map<String, dynamic> json) {
return _State.fromJson(json);
}
/// @nodoc
mixin _$State {
bool get has_chosen_diet => throw _privateConstructorUsedError;
bool get has_chosen_plan => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$StateCopyWith<State> get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $StateCopyWith<$Res> {
factory $StateCopyWith(State value, $Res Function(State) then) =
_$StateCopyWithImpl<$Res, State>;
@useResult
$Res call({bool has_chosen_diet, bool has_chosen_plan});
}
/// @nodoc
class _$StateCopyWithImpl<$Res, $Val extends State>
implements $StateCopyWith<$Res> {
_$StateCopyWithImpl(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? has_chosen_diet = null,
Object? has_chosen_plan = null,
}) {
return _then(_value.copyWith(
has_chosen_diet: null == has_chosen_diet
? _value.has_chosen_diet
: has_chosen_diet // ignore: cast_nullable_to_non_nullable
as bool,
has_chosen_plan: null == has_chosen_plan
? _value.has_chosen_plan
: has_chosen_plan // ignore: cast_nullable_to_non_nullable
as bool,
) as $Val);
}
}
/// @nodoc
abstract class _$$StateImplCopyWith<$Res> implements $StateCopyWith<$Res> {
factory _$$StateImplCopyWith(
_$StateImpl value, $Res Function(_$StateImpl) then) =
__$$StateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({bool has_chosen_diet, bool has_chosen_plan});
}
/// @nodoc
class __$$StateImplCopyWithImpl<$Res>
extends _$StateCopyWithImpl<$Res, _$StateImpl>
implements _$$StateImplCopyWith<$Res> {
__$$StateImplCopyWithImpl(
_$StateImpl _value, $Res Function(_$StateImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? has_chosen_diet = null,
Object? has_chosen_plan = null,
}) {
return _then(_$StateImpl(
has_chosen_diet: null == has_chosen_diet
? _value.has_chosen_diet
: has_chosen_diet // ignore: cast_nullable_to_non_nullable
as bool,
has_chosen_plan: null == has_chosen_plan
? _value.has_chosen_plan
: has_chosen_plan // ignore: cast_nullable_to_non_nullable
as bool,
));
}
}
/// @nodoc
@JsonSerializable()
class _$StateImpl implements _State {
const _$StateImpl(
{required this.has_chosen_diet, required this.has_chosen_plan});
factory _$StateImpl.fromJson(Map<String, dynamic> json) =>
_$$StateImplFromJson(json);
@override
final bool has_chosen_diet;
@override
final bool has_chosen_plan;
@override
String toString() {
return 'State(has_chosen_diet: $has_chosen_diet, has_chosen_plan: $has_chosen_plan)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$StateImpl &&
(identical(other.has_chosen_diet, has_chosen_diet) ||
other.has_chosen_diet == has_chosen_diet) &&
(identical(other.has_chosen_plan, has_chosen_plan) ||
other.has_chosen_plan == has_chosen_plan));
}
@JsonKey(ignore: true)
@override
int get hashCode =>
Object.hash(runtimeType, has_chosen_diet, has_chosen_plan);
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$StateImplCopyWith<_$StateImpl> get copyWith =>
__$$StateImplCopyWithImpl<_$StateImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$StateImplToJson(
this,
);
}
}
abstract class _State implements State {
const factory _State(
{required final bool has_chosen_diet,
required final bool has_chosen_plan}) = _$StateImpl;
factory _State.fromJson(Map<String, dynamic> json) = _$StateImpl.fromJson;
@override
bool get has_chosen_diet;
@override
bool get has_chosen_plan;
@override
@JsonKey(ignore: true)
_$$StateImplCopyWith<_$StateImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -0,0 +1,18 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'state.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_$StateImpl _$$StateImplFromJson(Map<String, dynamic> json) => _$StateImpl(
has_chosen_diet: json['has_chosen_diet'] as bool,
has_chosen_plan: json['has_chosen_plan'] as bool,
);
Map<String, dynamic> _$$StateImplToJson(_$StateImpl instance) =>
<String, dynamic>{
'has_chosen_diet': instance.has_chosen_diet,
'has_chosen_plan': instance.has_chosen_plan,
};