feat(profile): subscribers and subscriptions

This commit is contained in:
mso7nueh
2024-11-22 15:27:51 +03:00
parent f805505cb3
commit c909c75d47
45 changed files with 2790 additions and 451 deletions

View File

@@ -12,7 +12,6 @@ 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,
@@ -22,11 +21,16 @@ class DiaryCubit extends Cubit<DiaryState> {
getDiaryDay(String date, [bool needLoading = true]) async {
if (needLoading) emit(const DiaryState.loading());
try {
final diaryDay = await diaryRepository.getDiaryByDate(date);
final List<int> satiety = [];
for (int i = 0; i < diaryDay.meals.length; i++) {
satiety.add(diaryDay.meals[i].satiety);
}
emit(
DiaryState.loaded(
diary: await diaryRepository.getDiaryByDate(date),
diary: diaryDay,
nutrition: await getNutrition((await diaryRepository.getDiaryByDate(date)).id),
currentSelectedSatietyRating: currentSelectedSatietyRating,
currentSelectedSatietyRating: satiety,
),
);
} catch (e) {
@@ -136,17 +140,23 @@ class DiaryCubit extends Cubit<DiaryState> {
await getDiaryDay(date, false);
}
updateCurrentSelectedSatietyRating(double value) {
currentSelectedSatietyRating = value;
emit((state as DiaryStateLoaded).copyWith(currentSelectedSatietyRating: currentSelectedSatietyRating));
updateCurrentSelectedSatietyRating({
required int diaryId,
required int meal,
required int value,
}) {
List<int> satiety = [...(state as DiaryStateLoaded).currentSelectedSatietyRating];
satiety[meal] = value;
diaryRepository.fillSatiety(diaryId: diaryId, meal: meal, satiety: value.toInt() - 1);
emit((state as DiaryStateLoaded).copyWith(currentSelectedSatietyRating: satiety));
}
sendProductToModeration({
required String name,
required int energy,
required int proteins,
required int fats,
required int carbohydrates,
required double energy,
required double proteins,
required double fats,
required double carbohydrates,
}) async {
return await diaryRepository.sendProductToModeration(
name: name,

View File

@@ -17,6 +17,6 @@ class DiaryState with _$DiaryState {
const factory DiaryState.loaded({
required DiaryDayModel diary,
required NutritionDataModel nutrition,
required double currentSelectedSatietyRating,
required List<int> currentSelectedSatietyRating,
}) = DiaryStateLoaded;
}

View File

@@ -22,7 +22,7 @@ mixin _$DiaryState {
required TResult Function() loading,
required TResult Function(String errorMessage) error,
required TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
double currentSelectedSatietyRating)
List<int> currentSelectedSatietyRating)
loaded,
}) =>
throw _privateConstructorUsedError;
@@ -32,7 +32,7 @@ mixin _$DiaryState {
TResult? Function()? loading,
TResult? Function(String errorMessage)? error,
TResult? Function(DiaryDayModel diary, NutritionDataModel nutrition,
double currentSelectedSatietyRating)?
List<int> currentSelectedSatietyRating)?
loaded,
}) =>
throw _privateConstructorUsedError;
@@ -42,7 +42,7 @@ mixin _$DiaryState {
TResult Function()? loading,
TResult Function(String errorMessage)? error,
TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
double currentSelectedSatietyRating)?
List<int> currentSelectedSatietyRating)?
loaded,
required TResult orElse(),
}) =>
@@ -140,7 +140,7 @@ class _$DiaryStateImpl implements _DiaryState {
required TResult Function() loading,
required TResult Function(String errorMessage) error,
required TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
double currentSelectedSatietyRating)
List<int> currentSelectedSatietyRating)
loaded,
}) {
return $default();
@@ -153,7 +153,7 @@ class _$DiaryStateImpl implements _DiaryState {
TResult? Function()? loading,
TResult? Function(String errorMessage)? error,
TResult? Function(DiaryDayModel diary, NutritionDataModel nutrition,
double currentSelectedSatietyRating)?
List<int> currentSelectedSatietyRating)?
loaded,
}) {
return $default?.call();
@@ -166,7 +166,7 @@ class _$DiaryStateImpl implements _DiaryState {
TResult Function()? loading,
TResult Function(String errorMessage)? error,
TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
double currentSelectedSatietyRating)?
List<int> currentSelectedSatietyRating)?
loaded,
required TResult orElse(),
}) {
@@ -263,7 +263,7 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
required TResult Function() loading,
required TResult Function(String errorMessage) error,
required TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
double currentSelectedSatietyRating)
List<int> currentSelectedSatietyRating)
loaded,
}) {
return loading();
@@ -276,7 +276,7 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
TResult? Function()? loading,
TResult? Function(String errorMessage)? error,
TResult? Function(DiaryDayModel diary, NutritionDataModel nutrition,
double currentSelectedSatietyRating)?
List<int> currentSelectedSatietyRating)?
loaded,
}) {
return loading?.call();
@@ -289,7 +289,7 @@ class _$DiaryStateLoadingImpl implements DiaryStateLoading {
TResult Function()? loading,
TResult Function(String errorMessage)? error,
TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
double currentSelectedSatietyRating)?
List<int> currentSelectedSatietyRating)?
loaded,
required TResult orElse(),
}) {
@@ -415,7 +415,7 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
required TResult Function() loading,
required TResult Function(String errorMessage) error,
required TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
double currentSelectedSatietyRating)
List<int> currentSelectedSatietyRating)
loaded,
}) {
return error(errorMessage);
@@ -428,7 +428,7 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
TResult? Function()? loading,
TResult? Function(String errorMessage)? error,
TResult? Function(DiaryDayModel diary, NutritionDataModel nutrition,
double currentSelectedSatietyRating)?
List<int> currentSelectedSatietyRating)?
loaded,
}) {
return error?.call(errorMessage);
@@ -441,7 +441,7 @@ class _$DiaryStateErrorImpl implements DiaryStateError {
TResult Function()? loading,
TResult Function(String errorMessage)? error,
TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
double currentSelectedSatietyRating)?
List<int> currentSelectedSatietyRating)?
loaded,
required TResult orElse(),
}) {
@@ -511,7 +511,7 @@ abstract class _$$DiaryStateLoadedImplCopyWith<$Res> {
$Res call(
{DiaryDayModel diary,
NutritionDataModel nutrition,
double currentSelectedSatietyRating});
List<int> currentSelectedSatietyRating});
$DiaryDayModelCopyWith<$Res> get diary;
$NutritionDataModelCopyWith<$Res> get nutrition;
@@ -544,9 +544,9 @@ class __$$DiaryStateLoadedImplCopyWithImpl<$Res>
: nutrition // ignore: cast_nullable_to_non_nullable
as NutritionDataModel,
currentSelectedSatietyRating: null == currentSelectedSatietyRating
? _value.currentSelectedSatietyRating
? _value._currentSelectedSatietyRating
: currentSelectedSatietyRating // ignore: cast_nullable_to_non_nullable
as double,
as List<int>,
));
}
@@ -577,14 +577,21 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
const _$DiaryStateLoadedImpl(
{required this.diary,
required this.nutrition,
required this.currentSelectedSatietyRating});
required final List<int> currentSelectedSatietyRating})
: _currentSelectedSatietyRating = currentSelectedSatietyRating;
@override
final DiaryDayModel diary;
@override
final NutritionDataModel nutrition;
final List<int> _currentSelectedSatietyRating;
@override
final double currentSelectedSatietyRating;
List<int> get currentSelectedSatietyRating {
if (_currentSelectedSatietyRating is EqualUnmodifiableListView)
return _currentSelectedSatietyRating;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_currentSelectedSatietyRating);
}
@override
String toString() {
@@ -599,15 +606,14 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
(identical(other.diary, diary) || other.diary == diary) &&
(identical(other.nutrition, nutrition) ||
other.nutrition == nutrition) &&
(identical(other.currentSelectedSatietyRating,
currentSelectedSatietyRating) ||
other.currentSelectedSatietyRating ==
currentSelectedSatietyRating));
const DeepCollectionEquality().equals(
other._currentSelectedSatietyRating,
_currentSelectedSatietyRating));
}
@override
int get hashCode =>
Object.hash(runtimeType, diary, nutrition, currentSelectedSatietyRating);
int get hashCode => Object.hash(runtimeType, diary, nutrition,
const DeepCollectionEquality().hash(_currentSelectedSatietyRating));
/// Create a copy of DiaryState
/// with the given fields replaced by the non-null parameter values.
@@ -625,7 +631,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
required TResult Function() loading,
required TResult Function(String errorMessage) error,
required TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
double currentSelectedSatietyRating)
List<int> currentSelectedSatietyRating)
loaded,
}) {
return loaded(diary, nutrition, currentSelectedSatietyRating);
@@ -638,7 +644,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
TResult? Function()? loading,
TResult? Function(String errorMessage)? error,
TResult? Function(DiaryDayModel diary, NutritionDataModel nutrition,
double currentSelectedSatietyRating)?
List<int> currentSelectedSatietyRating)?
loaded,
}) {
return loaded?.call(diary, nutrition, currentSelectedSatietyRating);
@@ -651,7 +657,7 @@ class _$DiaryStateLoadedImpl implements DiaryStateLoaded {
TResult Function()? loading,
TResult Function(String errorMessage)? error,
TResult Function(DiaryDayModel diary, NutritionDataModel nutrition,
double currentSelectedSatietyRating)?
List<int> currentSelectedSatietyRating)?
loaded,
required TResult orElse(),
}) {
@@ -703,12 +709,12 @@ abstract class DiaryStateLoaded implements DiaryState {
const factory DiaryStateLoaded(
{required final DiaryDayModel diary,
required final NutritionDataModel nutrition,
required final double currentSelectedSatietyRating}) =
required final List<int> currentSelectedSatietyRating}) =
_$DiaryStateLoadedImpl;
DiaryDayModel get diary;
NutritionDataModel get nutrition;
double get currentSelectedSatietyRating;
List<int> get currentSelectedSatietyRating;
/// Create a copy of DiaryState
/// with the given fields replaced by the non-null parameter values.