feat(diary):

This commit is contained in:
mso7nueh
2024-11-11 04:57:41 +03:00
parent e3fc4811b8
commit 9b7e972268
5 changed files with 264 additions and 190 deletions

View File

@@ -10,6 +10,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
class DiaryCubit extends Cubit<DiaryState> {
final DiaryRepository diaryRepository;
final GlossaryRepository glossaryRepository;
double currentSelectedSatietyRating = 3;
DiaryCubit({
required this.diaryRepository,
@@ -19,7 +20,12 @@ class DiaryCubit extends Cubit<DiaryState> {
getDiaryDay(String date, [bool needLoading = true]) async {
if (needLoading) emit(const DiaryState.loading());
try {
emit(DiaryState.loaded(diary: await diaryRepository.getDiaryByDate(date)));
emit(
DiaryState.loaded(
diary: await diaryRepository.getDiaryByDate(date),
currentSelectedSatietyRating: currentSelectedSatietyRating,
),
);
} catch (e) {
emit(DiaryState.error(errorMessage: e.toString()));
throw e;
@@ -109,4 +115,9 @@ class DiaryCubit extends Cubit<DiaryState> {
);
await getDiaryDay(date, false);
}
updateCurrentSelectedSatietyRating(double value) {
currentSelectedSatietyRating = value;
emit((state as DiaryStateLoaded).copyWith(currentSelectedSatietyRating: currentSelectedSatietyRating));
}
}

View File

@@ -15,5 +15,6 @@ class DiaryState with _$DiaryState {
const factory DiaryState.loaded({
required DiaryDayModel diary,
required double currentSelectedSatietyRating,
}) = DiaryStateLoaded;
}

View File

@@ -21,7 +21,9 @@ mixin _$DiaryState {
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(String errorMessage) error,
required TResult Function(DiaryDayModel diary) loaded,
required TResult Function(
DiaryDayModel diary, double currentSelectedSatietyRating)
loaded,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
@@ -29,7 +31,8 @@ mixin _$DiaryState {
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(String errorMessage)? error,
TResult? Function(DiaryDayModel diary)? loaded,
TResult? Function(DiaryDayModel diary, double currentSelectedSatietyRating)?
loaded,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
@@ -37,7 +40,8 @@ mixin _$DiaryState {
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(String errorMessage)? error,
TResult Function(DiaryDayModel diary)? loaded,
TResult Function(DiaryDayModel diary, double currentSelectedSatietyRating)?
loaded,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@@ -133,7 +137,9 @@ class _$DiaryStateImpl implements _DiaryState {
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(String errorMessage) error,
required TResult Function(DiaryDayModel diary) loaded,
required TResult Function(
DiaryDayModel diary, double currentSelectedSatietyRating)
loaded,
}) {
return $default();
}
@@ -144,7 +150,8 @@ class _$DiaryStateImpl implements _DiaryState {
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(String errorMessage)? error,
TResult? Function(DiaryDayModel diary)? loaded,
TResult? Function(DiaryDayModel diary, double currentSelectedSatietyRating)?
loaded,
}) {
return $default?.call();
}
@@ -155,7 +162,8 @@ class _$DiaryStateImpl implements _DiaryState {
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(String errorMessage)? error,
TResult Function(DiaryDayModel diary)? loaded,
TResult Function(DiaryDayModel diary, double currentSelectedSatietyRating)?
loaded,
required TResult orElse(),
}) {
if ($default != null) {
@@ -250,7 +258,9 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(String errorMessage) error,
required TResult Function(DiaryDayModel diary) loaded,
required TResult Function(
DiaryDayModel diary, double currentSelectedSatietyRating)
loaded,
}) {
return loading();
}
@@ -261,7 +271,8 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(String errorMessage)? error,
TResult? Function(DiaryDayModel diary)? loaded,
TResult? Function(DiaryDayModel diary, double currentSelectedSatietyRating)?
loaded,
}) {
return loading?.call();
}
@@ -272,7 +283,8 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(String errorMessage)? error,
TResult Function(DiaryDayModel diary)? loaded,
TResult Function(DiaryDayModel diary, double currentSelectedSatietyRating)?
loaded,
required TResult orElse(),
}) {
if (loading != null) {
@@ -396,7 +408,9 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(String errorMessage) error,
required TResult Function(DiaryDayModel diary) loaded,
required TResult Function(
DiaryDayModel diary, double currentSelectedSatietyRating)
loaded,
}) {
return error(errorMessage);
}
@@ -407,7 +421,8 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(String errorMessage)? error,
TResult? Function(DiaryDayModel diary)? loaded,
TResult? Function(DiaryDayModel diary, double currentSelectedSatietyRating)?
loaded,
}) {
return error?.call(errorMessage);
}
@@ -418,7 +433,8 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(String errorMessage)? error,
TResult Function(DiaryDayModel diary)? loaded,
TResult Function(DiaryDayModel diary, double currentSelectedSatietyRating)?
loaded,
required TResult orElse(),
}) {
if (error != null) {
@@ -484,7 +500,7 @@ abstract class _$$DiaryStateLoadedImplCopyWith<$Res> {
$Res Function(_$DiaryStateLoadedImpl) then) =
__$$DiaryStateLoadedImplCopyWithImpl<$Res>;
@useResult
$Res call({DiaryDayModel diary});
$Res call({DiaryDayModel diary, double currentSelectedSatietyRating});
$DiaryDayModelCopyWith<$Res> get diary;
}
@@ -503,12 +519,17 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res>
@override
$Res call({
Object? diary = null,
Object? currentSelectedSatietyRating = null,
}) {
return _then(_$DiaryStateLoadedImpl(
diary: null == diary
? _value.diary
: diary // ignore: cast_nullable_to_non_nullable
as DiaryDayModel,
currentSelectedSatietyRating: null == currentSelectedSatietyRating
? _value.currentSelectedSatietyRating
: currentSelectedSatietyRating // ignore: cast_nullable_to_non_nullable
as double,
));
}
@@ -526,14 +547,17 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res>
/// @nodoc
class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
const _$DiaryStateLoadedImpl({required this.diary});
const _$DiaryStateLoadedImpl(
{required this.diary, required this.currentSelectedSatietyRating});
@override
final DiaryDayModel diary;
@override
final double currentSelectedSatietyRating;
@override
String toString() {
return 'DiaryState.loaded(diary: $diary)';
return 'DiaryState.loaded(diary: $diary, currentSelectedSatietyRating: $currentSelectedSatietyRating)';
}
@override
@@ -541,11 +565,16 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$DiaryStateLoadedImpl &&
(identical(other.diary, diary) || other.diary == diary));
(identical(other.diary, diary) || other.diary == diary) &&
(identical(other.currentSelectedSatietyRating,
currentSelectedSatietyRating) ||
other.currentSelectedSatietyRating ==
currentSelectedSatietyRating));
}
@override
int get hashCode => Object.hash(runtimeType, diary);
int get hashCode =>
Object.hash(runtimeType, diary, currentSelectedSatietyRating);
/// Create a copy of DiaryState
/// with the given fields replaced by the non-null parameter values.
@@ -562,9 +591,11 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(String errorMessage) error,
required TResult Function(DiaryDayModel diary) loaded,
required TResult Function(
DiaryDayModel diary, double currentSelectedSatietyRating)
loaded,
}) {
return loaded(diary);
return loaded(diary, currentSelectedSatietyRating);
}
@override
@@ -573,9 +604,10 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(String errorMessage)? error,
TResult? Function(DiaryDayModel diary)? loaded,
TResult? Function(DiaryDayModel diary, double currentSelectedSatietyRating)?
loaded,
}) {
return loaded?.call(diary);
return loaded?.call(diary, currentSelectedSatietyRating);
}
@override
@@ -584,11 +616,12 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(String errorMessage)? error,
TResult Function(DiaryDayModel diary)? loaded,
TResult Function(DiaryDayModel diary, double currentSelectedSatietyRating)?
loaded,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(diary);
return loaded(diary, currentSelectedSatietyRating);
}
return orElse();
}
@@ -632,10 +665,13 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
}
abstract class DiaryStateLoaded implements DiaryState {
const factory DiaryStateLoaded({required final DiaryDayModel diary}) =
const factory DiaryStateLoaded(
{required final DiaryDayModel diary,
required final double currentSelectedSatietyRating}) =
_$DiaryStateLoadedImpl;
DiaryDayModel get diary;
double get currentSelectedSatietyRating;
/// Create a copy of DiaryState
/// with the given fields replaced by the non-null parameter values.