forked from eatvio/eatvio_app
diet creation scrren is done
This commit is contained in:
@@ -1,11 +1,72 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:eatvio_app/features/plans/presentation/cubit/about_plan_state.dart';
|
||||
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class AboutPlanCubit extends Cubit<AboutPlanState> {
|
||||
AboutPlanCubit() : super(AboutPlanState.initial());
|
||||
final PlanRepository planRepository;
|
||||
AboutPlanCubit({required this.planRepository}) : super(AboutPlanState.initial());
|
||||
|
||||
Future<void> getPlan(String slug) async {
|
||||
try {
|
||||
final plan = await planRepository.getPlan(slug);
|
||||
emit(state.copyWith(planModel: plan, error: null));
|
||||
} catch (e, stackTrace) {
|
||||
log(e.toString(), stackTrace: stackTrace);
|
||||
emit(state.copyWith(error: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> getPlan() async{
|
||||
Future<void> getPlanWithLoading(String slug) async {
|
||||
try {
|
||||
emit(state.copyWith(isLoading: true));
|
||||
final plan = await planRepository.getPlan(slug);
|
||||
emit(state.copyWith(
|
||||
planModel: plan,
|
||||
error: null,
|
||||
isLoading: false,
|
||||
),);
|
||||
} catch (e, stackTrace) {
|
||||
log(e.toString(), stackTrace: stackTrace);
|
||||
emit(state.copyWith(error: e.toString(), isLoading: false));
|
||||
}
|
||||
}
|
||||
|
||||
void choseOption(int index) {
|
||||
emit(state.copyWith(chosenOptionIndex: index));
|
||||
}
|
||||
|
||||
Future<void> likePlan(String slug) async {
|
||||
try {
|
||||
await planRepository.likePlan(slug);
|
||||
final plan = await planRepository.getPlan(slug);
|
||||
emit(state.copyWith(planModel: plan, error: null));
|
||||
} catch (e, stackTrace) {
|
||||
log(e.toString(), stackTrace: stackTrace);
|
||||
emit(state.copyWith(error: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addToFavorite(String slug) async {
|
||||
try {
|
||||
await planRepository.addToFavorite(slug);
|
||||
final plan = await planRepository.getPlan(slug);
|
||||
emit(state.copyWith(planModel: plan, error: null));
|
||||
} catch (e, stackTrace) {
|
||||
log(e.toString(), stackTrace: stackTrace);
|
||||
emit(state.copyWith(error: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> removeFromFavorite(String slug) async {
|
||||
try {
|
||||
await planRepository.removeFromFavorite(slug);
|
||||
final plan = await planRepository.getPlan(slug);
|
||||
emit(state.copyWith(planModel: plan, error: null));
|
||||
} catch (e, stackTrace) {
|
||||
log(e.toString(), stackTrace: stackTrace);
|
||||
emit(state.copyWith(error: e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user