my plans and my diets

This commit is contained in:
Username1548
2024-12-23 15:36:00 +07:00
parent 15a6ff44ef
commit 5ef1f3a660
52 changed files with 3857 additions and 573 deletions

View File

@@ -42,15 +42,19 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
emit(state.copyWith(chosenOptionIndex: index));
}
Future<void> likePlan({required int index, required String slug}) async {
Future<void> likePlan({required int? index, required String slug}) async {
final currentPlan = state.planModel;
if (currentPlan == null) return;
if (currentPlan.wasLikedByMe) {
emit(state.copyWith(planModel: currentPlan.copyWith(wasLikedByMe: false, totalLikes: currentPlan.totalLikes - 1), error: null));
planRepository.emitLikesStateToFeed(LikesState(wasLikedByMe: false, totalLikes: currentPlan.totalLikes - 1, index: index));
if (index != null) {
planRepository.emitLikesStateToFeed(LikesState(wasLikedByMe: false, totalLikes: currentPlan.totalLikes - 1, index: index));
}
} else {
emit(state.copyWith(planModel: currentPlan.copyWith(wasLikedByMe: true, totalLikes: currentPlan.totalLikes + 1), error: null));
planRepository.emitLikesStateToFeed(LikesState(wasLikedByMe: true, totalLikes: currentPlan.totalLikes + 1, index: index));
if (index != null) {
planRepository.emitLikesStateToFeed(LikesState(wasLikedByMe: true, totalLikes: currentPlan.totalLikes + 1, index: index));
}
}
EasyDebounce.debounce(
@@ -61,19 +65,23 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
await planRepository.likePlan(slug);
} catch (e) {
log(e.toString());
planRepository.emitLikesStateToFeed(LikesState(wasLikedByMe: currentPlan.wasLikedByMe, totalLikes: currentPlan.totalLikes, index: index));
if (index != null) {
planRepository.emitLikesStateToFeed(LikesState(wasLikedByMe: currentPlan.wasLikedByMe, totalLikes: currentPlan.totalLikes, index: index));
}
emit(state.copyWith(planModel: currentPlan, error: null));
}
},
);
}
Future<void> addToFavorite({required String slug, required int index}) async {
Future<void> addToFavorite({required String slug, required int? index}) async {
final currentPlan = state.planModel;
if (currentPlan == null) return;
emit(state.copyWith(planModel: currentPlan.copyWith(isFavorite: true)));
planRepository.emitFavoriteStateToFeed(FavoriteState(isFavorite: true, index: index));
if (index != null) {
planRepository.emitFavoriteStateToFeed(FavoriteState(isFavorite: true, index: index));
}
EasyDebounce.debounce(
'add_or_remove_plan_to_favorites',
Duration(seconds: 1),
@@ -83,19 +91,23 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
} catch (e) {
log(e.toString());
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
planRepository.emitFavoriteStateToFeed(FavoriteState(isFavorite: currentPlan.isFavorite, index: index));
if (index != null) {
planRepository.emitFavoriteStateToFeed(FavoriteState(isFavorite: currentPlan.isFavorite, index: index));
}
emit(state.copyWith(planModel: currentPlan, error: null));
}
},
);
}
Future<void> removeFromFavorite({required String slug, required int index}) async {
Future<void> removeFromFavorite({required String slug, required int? index}) async {
final currentPlan = state.planModel;
if (currentPlan == null) return;
emit(state.copyWith(planModel: currentPlan.copyWith(isFavorite: false)));
planRepository.emitFavoriteStateToFeed(FavoriteState(isFavorite: false, index: index));
if (index != null) {
planRepository.emitFavoriteStateToFeed(FavoriteState(isFavorite: false, index: index));
}
EasyDebounce.debounce(
'add_or_remove_plan_to_favorites',
Duration(seconds: 1),
@@ -105,7 +117,9 @@ class AboutPlanCubit extends Cubit<AboutPlanState> {
} catch (e) {
log(e.toString());
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
planRepository.emitFavoriteStateToFeed(FavoriteState(isFavorite: currentPlan.isFavorite, index: currentPlan.id));
if (index != null) {
planRepository.emitFavoriteStateToFeed(FavoriteState(isFavorite: currentPlan.isFavorite, index: index));
}
emit(state.copyWith(planModel: currentPlan, error: null));
}
},

View File

@@ -5,7 +5,7 @@ import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/core/utils/localization_utils.dart';
import 'package:eatvio_app/core/utils/string_extentions.dart';
import 'package:eatvio_app/core/widgets/bookmark_button.dart';
import 'package:eatvio_app/core/widgets/diet_info_row.dart';
import 'package:eatvio_app/core/widgets/info_row.dart';
import 'package:eatvio_app/core/widgets/loader.dart';
import 'package:eatvio_app/features/diets/presentation/widgets/author_card.dart';
import 'package:eatvio_app/features/diets/presentation/widgets/expandable_text.dart';
@@ -34,7 +34,7 @@ class AboutPlanScreen extends StatefulWidget {
AboutPlanScreen({super.key, required this.plan, required this.navigateToComments, required this.index});
final PlanModel plan;
final bool navigateToComments;
final int index;
final int? index;
@override
State<AboutPlanScreen> createState() => _AboutPlanScreenState();
}