forked from eatvio/eatvio_app
feat(diary): add diary, calendar, meals, products, add product button, modal add product
This commit is contained in:
@@ -1,17 +1,20 @@
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
|
||||
import 'package:eatvio_app/features/diary/repositories/diary_repository.dart';
|
||||
import 'package:eatvio_app/features/glossary/models/glossary_model.dart';
|
||||
import 'package:eatvio_app/features/glossary/repositories/glossary_repository.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class DiaryCubit extends Cubit<DiaryState> {
|
||||
final DiaryRepository diaryRepository;
|
||||
final GlossaryRepository glossaryRepository;
|
||||
|
||||
DiaryCubit({
|
||||
required this.diaryRepository,
|
||||
required this.glossaryRepository,
|
||||
}) : super(const DiaryState.loading());
|
||||
|
||||
getDiaryDay(String date) async {
|
||||
print(date);
|
||||
emit(const DiaryState.loading());
|
||||
getDiaryDay(String date, [bool needLoading = true]) async {
|
||||
if (needLoading) emit(const DiaryState.loading());
|
||||
try {
|
||||
emit(DiaryState.loaded(diary: await diaryRepository.getDiaryByDate(date)));
|
||||
} catch (e) {
|
||||
@@ -19,4 +22,26 @@ class DiaryCubit extends Cubit<DiaryState> {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
addProductToMeal({
|
||||
required int diaryId,
|
||||
required int mealId,
|
||||
required String productName,
|
||||
required String portion,
|
||||
required int quantity,
|
||||
required String date,
|
||||
}) async {
|
||||
await diaryRepository.addPortionToMeal(
|
||||
diaryId: diaryId,
|
||||
mealId: mealId,
|
||||
productName: productName,
|
||||
portion: portion,
|
||||
quantity: quantity,
|
||||
);
|
||||
await getDiaryDay(date, false);
|
||||
}
|
||||
|
||||
Future<List<GlossaryModel>> getGlossaryListByQuery(String query) async {
|
||||
return await glossaryRepository.getGlossaryListByQuery(query);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user