forked from eatvio/eatvio_app
feat(diary): fixed bugs fod diary with v2 methods
This commit is contained in:
@@ -60,24 +60,17 @@ abstract class DiaryDayModel with _$DiaryDayModel {
|
|||||||
meals: meals,
|
meals: meals,
|
||||||
chosenPlanId: chosenPlanId,
|
chosenPlanId: chosenPlanId,
|
||||||
dayOfChosenDiet: dayOfChosenDiet,
|
dayOfChosenDiet: dayOfChosenDiet,
|
||||||
|
wakeup: wakeup,
|
||||||
|
retire: retire,
|
||||||
diet: diet,
|
diet: diet,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
DiaryFutureDietDayEntity toDiaryFutureDayEntity() {
|
DiaryFutureDietDayEntity toDiaryFutureDayEntity() {
|
||||||
|
return DiaryFutureDietDayEntity(date: date, typeOfDiary: typeOfDiary, meals: meals, dayOfChosenDiet: dayOfChosenDiet, diet: diet);
|
||||||
return DiaryFutureDietDayEntity(
|
|
||||||
date: date,
|
|
||||||
typeOfDiary: typeOfDiary,
|
|
||||||
meals: meals,
|
|
||||||
dayOfChosenDiet: dayOfChosenDiet,
|
|
||||||
diet: diet,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DiaryDietModel? parseDiet(dynamic json) {
|
DiaryDietModel? parseDiet(dynamic json) {
|
||||||
if (json == null) return null;
|
if (json == null) return null;
|
||||||
return DiaryDietModel.fromJson(json['diet']);
|
return DiaryDietModel.fromJson(json['diet']);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
|||||||
class DiaryCubit extends Cubit<DiaryState> {
|
class DiaryCubit extends Cubit<DiaryState> {
|
||||||
late final DateTime today;
|
late final DateTime today;
|
||||||
late DateTime selectedDay;
|
late DateTime selectedDay;
|
||||||
late int selectedMeal;
|
int selectedMeal = 1;
|
||||||
final DiaryRepository diaryRepository;
|
final DiaryRepository diaryRepository;
|
||||||
final GlossaryRepository glossaryRepository;
|
final GlossaryRepository glossaryRepository;
|
||||||
final ProfileRepository profileRepository;
|
final ProfileRepository profileRepository;
|
||||||
@@ -48,44 +48,70 @@ class DiaryCubit extends Cubit<DiaryState> {
|
|||||||
|
|
||||||
String comment = '';
|
String comment = '';
|
||||||
|
|
||||||
Future<bool> setSelectedDay(DateTime day, {bool? forDietOnly}) async {
|
Future<bool> setSelectedDay(DateTime day) async {
|
||||||
selectedDay = day;
|
final canSelect = await fetchDiaryV2(needLoading: true);
|
||||||
if (forDietOnly ?? false) {
|
if (canSelect) {
|
||||||
final result = await fetchDiaryV2();
|
selectedDay = day;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
await fetchDiaryV2(needLoading: true);
|
return canSelect;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> fetchDiaryV2({bool needLoading = false, int? diaryId, int? currentDay}) async {
|
Future<bool> fetchDiaryV2({bool needLoading = false, int? diaryId}) async {
|
||||||
final (diaryDay, error) = await qwe();
|
final currentState = state;
|
||||||
if (error != null) {
|
if (needLoading) {
|
||||||
if (error == DiaryFetchingErrors.canNotCreateFutureDays) {
|
emit(const DiaryState.loading());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
emit(DiaryState.error(errorMessage: error.toString()));
|
|
||||||
}
|
}
|
||||||
|
if (diaryId != null) {
|
||||||
if (diaryDay != null) {
|
final diaryDayById = await diaryRepository.getDiaryDay(diaryId);
|
||||||
final diaryEntity = diaryDay.toEntity();
|
final diaryEntity = diaryDayById.toEntity();
|
||||||
if (diaryEntity != null) {
|
if (diaryEntity != null) {
|
||||||
setDiary(diaryDay: diaryEntity);
|
setDiary(diaryDay: diaryEntity, diaryId: diaryId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
setDiaryForDietOnly(diaryDay.toDiaryFutureDayEntity());
|
|
||||||
}
|
}
|
||||||
return true;
|
final diaryDay = await getDiary();
|
||||||
|
if (diaryDay == null) {
|
||||||
|
emit(const DiaryState.error(errorMessage: 'Diary not found'));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final diaryEntity = diaryDay.toEntity();
|
||||||
|
if (diaryEntity != null) {
|
||||||
|
setDiary(diaryDay: diaryEntity, diaryId: diaryId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (diaryDay.typeOfDiary.hasChosenDiet == true && diaryDay.typeOfDiary.diaryState == null) {
|
||||||
|
setDiaryForDietOnly(diaryDay.toDiaryFutureDayEntity());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
emit(currentState);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<(DiaryDayModel?, DiaryFetchingErrors?)> qwe() async {
|
Future<void> updateCurrentDiary() async {
|
||||||
try {
|
try {
|
||||||
final diaryDay = await diaryRepository.getDiaryDayV2(day: selectedDay.toISO8601WithTimeZoneOffset());
|
final diaryDay = await diaryRepository.getDiaryDayV2(day: selectedDay.toISO8601WithTimeZoneOffset());
|
||||||
} on DioException catch (e) {
|
final diaryEntity = diaryDay.toEntity();
|
||||||
|
if (diaryEntity != null) {
|
||||||
|
setDiary(diaryDay: diaryEntity, diaryId: diaryId);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log(e.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (null, null);
|
Future<DiaryDayModel?> getDiary() async {
|
||||||
|
try {
|
||||||
|
await diaryRepository.createDiaryDay(day: selectedDay.toISO8601WithTimeZoneOffset());
|
||||||
|
final diaryDay = await diaryRepository.getDiaryDayV2(day: selectedDay.toISO8601WithTimeZoneOffset());
|
||||||
|
return diaryDay;
|
||||||
|
} on DioException catch (e) {
|
||||||
|
if (e.response?.statusCode == 422) {
|
||||||
|
final diaryDay = await diaryRepository.getDiaryDayV2(day: selectedDay.toISO8601WithTimeZoneOffset());
|
||||||
|
return diaryDay;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSelectedMeal(int meal) {
|
void setSelectedMeal(int meal) {
|
||||||
@@ -177,18 +203,14 @@ class DiaryCubit extends Cubit<DiaryState> {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setDiary({int? diaryId, int? currentDay, required DiaryDayEntity diaryDay}) async {
|
Future<void> setDiary({int? diaryId, required DiaryDayEntity diaryDay}) async {
|
||||||
this.diaryId ??= diaryId;
|
this.diaryId ??= diaryId;
|
||||||
final isConsultantView = this.diaryId != null;
|
final isConsultantView = this.diaryId != null;
|
||||||
try {
|
try {
|
||||||
final DiaryDayModel diaryDay;
|
|
||||||
bool isMoodEnabled = false;
|
bool isMoodEnabled = false;
|
||||||
bool isWakeUpAndRetireTimeEnabled = false;
|
bool isWakeUpAndRetireTimeEnabled = false;
|
||||||
if (diaryId != null) {
|
if (diaryId != null) {
|
||||||
diaryDay = await diaryRepository.getDiaryDay(diaryId);
|
|
||||||
} else {
|
} else {
|
||||||
final stringDate = selectedDay.format('yyyy-MM-dd');
|
|
||||||
diaryDay = await diaryRepository.getDiaryByDate(stringDate);
|
|
||||||
final profileSettings = await settingsRepository.getProfileSettings();
|
final profileSettings = await settingsRepository.getProfileSettings();
|
||||||
isMoodEnabled = profileSettings.isMoodFillable;
|
isMoodEnabled = profileSettings.isMoodFillable;
|
||||||
isWakeUpAndRetireTimeEnabled = profileSettings.isBedtimeFillable;
|
isWakeUpAndRetireTimeEnabled = profileSettings.isBedtimeFillable;
|
||||||
@@ -201,14 +223,14 @@ class DiaryCubit extends Cubit<DiaryState> {
|
|||||||
final chosenPlanModel = await chatRepository.getChosenPlan(id: diaryDay.chosenPlanId!);
|
final chosenPlanModel = await chatRepository.getChosenPlan(id: diaryDay.chosenPlanId!);
|
||||||
if (!isConsultantView &&
|
if (!isConsultantView &&
|
||||||
(diaryDay.typeOfDiary.diaryState == DiaryStateEnum.lastDayCommented || diaryDay.typeOfDiary.diaryState == DiaryStateEnum.commented)) {
|
(diaryDay.typeOfDiary.diaryState == DiaryStateEnum.lastDayCommented || diaryDay.typeOfDiary.diaryState == DiaryStateEnum.commented)) {
|
||||||
await diaryRepository.viewCommentOfDiaryDayByConsultant(diaryId: diaryDay.id!);
|
await diaryRepository.viewCommentOfDiaryDayByConsultant(diaryId: diaryDay.id);
|
||||||
}
|
}
|
||||||
consultantReview = await diaryRepository.getDiaryComments(planId: diaryDay.chosenPlanId!, diaryId: diaryDay.id!);
|
consultantReview = await diaryRepository.getDiaryComments(planId: diaryDay.chosenPlanId!, diaryId: diaryDay.id);
|
||||||
planDuration = chosenPlanModel.plan.duration;
|
planDuration = chosenPlanModel.plan.duration;
|
||||||
planName = chosenPlanModel.plan.name;
|
planName = chosenPlanModel.plan.name;
|
||||||
currentPlanDay = consultantReview.currentPlanDay;
|
currentPlanDay = consultantReview.currentPlanDay;
|
||||||
}
|
}
|
||||||
final nutrition = await getNutrition(diaryDay.id!);
|
final nutrition = await getNutrition(diaryDay.id);
|
||||||
|
|
||||||
final isDiaryFinished = diaryDay.typeOfDiary.diaryState == DiaryStateEnum.finished || diaryDay.typeOfDiary.diaryState == DiaryStateEnum.lastDayFinished;
|
final isDiaryFinished = diaryDay.typeOfDiary.diaryState == DiaryStateEnum.finished || diaryDay.typeOfDiary.diaryState == DiaryStateEnum.lastDayFinished;
|
||||||
|
|
||||||
@@ -218,7 +240,7 @@ class DiaryCubit extends Cubit<DiaryState> {
|
|||||||
diaryDay.typeOfDiary.diaryState == DiaryStateEnum.reviewedByUser;
|
diaryDay.typeOfDiary.diaryState == DiaryStateEnum.reviewedByUser;
|
||||||
emit(
|
emit(
|
||||||
DiaryState.loaded(
|
DiaryState.loaded(
|
||||||
diary: diaryDay.toEntity()!,
|
diary: diaryDay,
|
||||||
nutrition: nutrition,
|
nutrition: nutrition,
|
||||||
selectedDay: selectedDay,
|
selectedDay: selectedDay,
|
||||||
selectedMeal: selectedMeal,
|
selectedMeal: selectedMeal,
|
||||||
@@ -241,7 +263,7 @@ class DiaryCubit extends Cubit<DiaryState> {
|
|||||||
|
|
||||||
Future<void> finishDiaryDay({required int diaryId, required String wakeUp, required String retire}) async {
|
Future<void> finishDiaryDay({required int diaryId, required String wakeUp, required String retire}) async {
|
||||||
await diaryRepository.finishDiaryDay(diaryId: diaryId, wakeUp: wakeUp, retire: retire, comment: comment.isEmpty ? null : comment);
|
await diaryRepository.finishDiaryDay(diaryId: diaryId, wakeUp: wakeUp, retire: retire, comment: comment.isEmpty ? null : comment);
|
||||||
await fetchDiaryV2();
|
await updateCurrentDiary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<NutritionDataModel> getNutrition(int index) async {
|
Future<NutritionDataModel> getNutrition(int index) async {
|
||||||
@@ -265,7 +287,7 @@ class DiaryCubit extends Cubit<DiaryState> {
|
|||||||
quantity: quantity,
|
quantity: quantity,
|
||||||
productNutritionalValueId: productNutritionalValueId,
|
productNutritionalValueId: productNutritionalValueId,
|
||||||
);
|
);
|
||||||
await fetchDiaryV2();
|
await updateCurrentDiary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> updateProductInMeal({
|
Future<void> updateProductInMeal({
|
||||||
@@ -299,27 +321,27 @@ class DiaryCubit extends Cubit<DiaryState> {
|
|||||||
portionState: portionState,
|
portionState: portionState,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await fetchDiaryV2();
|
await updateCurrentDiary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> markEaten({required int diaryId, required int mealId, required int portionId}) async {
|
Future<void> markEaten({required int diaryId, required int mealId, required int portionId}) async {
|
||||||
await diaryRepository.markEaten(diaryId: diaryId, mealId: mealId, portionId: portionId);
|
await diaryRepository.markEaten(diaryId: diaryId, mealId: mealId, portionId: portionId);
|
||||||
await fetchDiaryV2();
|
await updateCurrentDiary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> unmarkEaten({required int diaryId, required int mealId, required int portionId}) async {
|
Future<void> unmarkEaten({required int diaryId, required int mealId, required int portionId}) async {
|
||||||
await diaryRepository.unmarkEaten(diaryId: diaryId, mealId: mealId, portionId: portionId);
|
await diaryRepository.unmarkEaten(diaryId: diaryId, mealId: mealId, portionId: portionId);
|
||||||
await fetchDiaryV2();
|
await updateCurrentDiary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> restore({required int diaryId, required int mealId, required int portionId}) async {
|
Future<void> restore({required int diaryId, required int mealId, required int portionId}) async {
|
||||||
await diaryRepository.restore(diaryId: diaryId, mealId: mealId, portionId: portionId);
|
await diaryRepository.restore(diaryId: diaryId, mealId: mealId, portionId: portionId);
|
||||||
await fetchDiaryV2();
|
await updateCurrentDiary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deleteProductFromMeal({required int diaryId, required int mealId, required int portionId}) async {
|
Future<void> deleteProductFromMeal({required int diaryId, required int mealId, required int portionId}) async {
|
||||||
await diaryRepository.deleteProductFromMeal(diaryId: diaryId, mealId: mealId, portionId: portionId);
|
await diaryRepository.deleteProductFromMeal(diaryId: diaryId, mealId: mealId, portionId: portionId);
|
||||||
await fetchDiaryV2();
|
await updateCurrentDiary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<GlossaryModel>> getGlossaryListByQuery(String query) async {
|
Future<List<GlossaryModel>> getGlossaryListByQuery(String query) async {
|
||||||
@@ -328,12 +350,12 @@ class DiaryCubit extends Cubit<DiaryState> {
|
|||||||
|
|
||||||
Future<void> uploadPhotos({required List<File> files, required int diaryId}) async {
|
Future<void> uploadPhotos({required List<File> files, required int diaryId}) async {
|
||||||
await diaryRepository.uploadPhotos(files: await ImageCompressUtility.compressFilesList(files), diaryId: diaryId, mealId: selectedMeal);
|
await diaryRepository.uploadPhotos(files: await ImageCompressUtility.compressFilesList(files), diaryId: diaryId, mealId: selectedMeal);
|
||||||
await fetchDiaryV2();
|
await updateCurrentDiary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deletePhoto({required DiaryPhotoModel photo, required int diaryId}) async {
|
Future<void> deletePhoto({required DiaryPhotoModel photo, required int diaryId}) async {
|
||||||
await diaryRepository.deletePhoto(photo: photo, diaryId: diaryId, mealId: selectedMeal);
|
await diaryRepository.deletePhoto(photo: photo, diaryId: diaryId, mealId: selectedMeal);
|
||||||
await fetchDiaryV2();
|
await updateCurrentDiary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<GlossaryModerationModel?> sendProductToModeration({
|
Future<GlossaryModerationModel?> sendProductToModeration({
|
||||||
@@ -353,34 +375,32 @@ class DiaryCubit extends Cubit<DiaryState> {
|
|||||||
|
|
||||||
Future<void> fillTime({required int diaryId, required String time}) async {
|
Future<void> fillTime({required int diaryId, required String time}) async {
|
||||||
await diaryRepository.fillTime(diaryId: diaryId, mealId: selectedMeal, time: time);
|
await diaryRepository.fillTime(diaryId: diaryId, mealId: selectedMeal, time: time);
|
||||||
await fetchDiaryV2();
|
await updateCurrentDiary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> fillWakeup({required int diaryId, required String time}) async {
|
Future<void> fillWakeup({required int diaryId, required String time}) async {
|
||||||
await diaryRepository.fillWakeup(diaryId: diaryId, time: time);
|
await diaryRepository.fillWakeup(diaryId: diaryId, time: time);
|
||||||
await fetchDiaryV2();
|
await updateCurrentDiary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> fillRetire({required int diaryId, required String time}) async {
|
Future<void> fillRetire({required int diaryId, required String time}) async {
|
||||||
await diaryRepository.fillRetire(diaryId: diaryId, time: time);
|
await diaryRepository.fillRetire(diaryId: diaryId, time: time);
|
||||||
await fetchDiaryV2();
|
await updateCurrentDiary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> fillSatiety({required int diaryId, required int satiety}) async {
|
Future<void> fillSatiety({required int diaryId, required int satiety}) async {
|
||||||
await diaryRepository.fillSatiety(diaryId: diaryId, mealId: selectedMeal, satiety: satiety);
|
await diaryRepository.fillSatiety(diaryId: diaryId, mealId: selectedMeal, satiety: satiety);
|
||||||
await fetchDiaryV2();
|
await updateCurrentDiary();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> fillMood({required int diaryId, required int mood}) async {
|
Future<void> fillMood({required int diaryId, required int mood}) async {
|
||||||
await diaryRepository.fillMood(diaryId: diaryId, mealId: selectedMeal, mood: mood);
|
await diaryRepository.fillMood(diaryId: diaryId, mealId: selectedMeal, mood: mood);
|
||||||
await fetchDiaryV2();
|
await updateCurrentDiary();
|
||||||
}
|
}
|
||||||
|
|
||||||
void fillComment(String comment) {
|
void fillComment(String comment) {
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum DiaryFetchingErrors { canNotCreateFutureDays, dayAlreadyExists }
|
enum DiaryFetchingErrors { canNotCreateFutureDays, dayAlreadyExists }
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import 'package:eatvio_app/features/diary/entities/diary_day_entity.dart';
|
import 'package:eatvio_app/features/diary/entities/diary_day_entity.dart';
|
||||||
import 'package:eatvio_app/features/diary/entities/diary_future_diet_day_entity.dart';
|
import 'package:eatvio_app/features/diary/entities/diary_future_diet_day_entity.dart';
|
||||||
import 'package:eatvio_app/features/diary/models/consultant_review_model.dart';
|
import 'package:eatvio_app/features/diary/models/consultant_review_model.dart';
|
||||||
import 'package:eatvio_app/features/diary/models/diary_day_model.dart';
|
|
||||||
import 'package:eatvio_app/features/diary/models/nutrition_model.dart';
|
import 'package:eatvio_app/features/diary/models/nutrition_model.dart';
|
||||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class DiaryScreenContent extends StatelessWidget {
|
|||||||
final s = S.of(context);
|
final s = S.of(context);
|
||||||
return MultiBlocProvider(
|
return MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
BlocProvider<DiaryCubit>(create: (BuildContext context) => sl<DiaryCubit>()..fetchDiaryV2(needLoading: true, diaryId: diaryId, currentDay: currentPlanDay)),
|
BlocProvider<DiaryCubit>(create: (BuildContext context) => sl<DiaryCubit>()..fetchDiaryV2(needLoading: true, diaryId: diaryId)),
|
||||||
BlocProvider(create: (context) => sl<ConsultantCommentsCubit>()),
|
BlocProvider(create: (context) => sl<ConsultantCommentsCubit>()),
|
||||||
],
|
],
|
||||||
child: BlocBuilder<DiaryCubit, DiaryState>(
|
child: BlocBuilder<DiaryCubit, DiaryState>(
|
||||||
|
|||||||
@@ -43,46 +43,24 @@ class _CalendarWidgetState extends State<CalendarWidget> {
|
|||||||
locale: 'ru_RU',
|
locale: 'ru_RU',
|
||||||
startingDayOfWeek: StartingDayOfWeek.monday,
|
startingDayOfWeek: StartingDayOfWeek.monday,
|
||||||
calendarFormat: _calendarFormat,
|
calendarFormat: _calendarFormat,
|
||||||
headerStyle: const HeaderStyle(
|
headerStyle: const HeaderStyle(titleCentered: true, formatButtonVisible: false, leftChevronVisible: false, rightChevronVisible: false),
|
||||||
titleCentered: true,
|
|
||||||
formatButtonVisible: false,
|
|
||||||
leftChevronVisible: false,
|
|
||||||
rightChevronVisible: false,
|
|
||||||
),
|
|
||||||
onDaySelected: (selectedDay, focusedDay) async {
|
onDaySelected: (selectedDay, focusedDay) async {
|
||||||
if (!isSameDay(_selectedDay, selectedDay)) {
|
if (!isSameDay(_selectedDay, selectedDay)) {
|
||||||
final today = DateTime.now();
|
final previousSelectedDay = _selectedDay;
|
||||||
if (selectedDay.isAfter(today)) {
|
final previousFocusedDay = _selectedDay;
|
||||||
if ((state is DiaryStateLoaded)) {
|
|
||||||
final result = await context.read<DiaryCubit>().setSelectedDay(_selectedDay, forDietOnly: true);
|
|
||||||
if (result == false && context.mounted) {
|
|
||||||
showErrorDialog(context, title: s.want_to_see_tomorrow, description: s.can_not_see_next_day);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setState(() {
|
|
||||||
_selectedDay = selectedDay;
|
|
||||||
_focusedDay = focusedDay;
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (state is DiaryStateLoadedTomorrowWithDiet) {
|
|
||||||
final result = await context.read<DiaryCubit>().setSelectedDay(_selectedDay, forDietOnly: true);
|
|
||||||
if (result == false && context.mounted) {
|
|
||||||
showErrorDialog(context, title: s.want_to_see_tomorrow, description: s.can_not_see_next_day);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setState(() {
|
|
||||||
_selectedDay = selectedDay;
|
|
||||||
_focusedDay = focusedDay;
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_selectedDay = selectedDay;
|
_selectedDay = selectedDay;
|
||||||
_focusedDay = focusedDay;
|
_focusedDay = focusedDay;
|
||||||
});
|
});
|
||||||
context.read<DiaryCubit>().setSelectedDay(_selectedDay);
|
final canOpenNextDay = await context.read<DiaryCubit>().setSelectedDay(selectedDay);
|
||||||
|
if (!canOpenNextDay && context.mounted) {
|
||||||
|
showErrorDialog(context, title: s.want_to_see_tomorrow, description: s.can_not_see_next_day);
|
||||||
|
setState(() {
|
||||||
|
_selectedDay = previousSelectedDay;
|
||||||
|
_focusedDay = previousFocusedDay;
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
selectedDayPredicate: (day) {
|
selectedDayPredicate: (day) {
|
||||||
@@ -101,26 +79,12 @@ class _CalendarWidgetState extends State<CalendarWidget> {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
calendarStyle: CalendarStyle(
|
calendarStyle: CalendarStyle(
|
||||||
weekendDecoration: const BoxDecoration(
|
weekendDecoration: const BoxDecoration(color: Colors.white, shape: BoxShape.circle),
|
||||||
color: Colors.white,
|
defaultDecoration: const BoxDecoration(color: Colors.white, shape: BoxShape.circle),
|
||||||
shape: BoxShape.circle,
|
selectedDecoration: BoxDecoration(color: appTheme.blueA400, shape: BoxShape.circle),
|
||||||
),
|
todayTextStyle: const TextStyle(color: Colors.black),
|
||||||
defaultDecoration: const BoxDecoration(
|
|
||||||
color: Colors.white,
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
),
|
|
||||||
selectedDecoration: BoxDecoration(
|
|
||||||
color: appTheme.blueA400,
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
),
|
|
||||||
todayTextStyle: const TextStyle(
|
|
||||||
color: Colors.black,
|
|
||||||
),
|
|
||||||
todayDecoration: BoxDecoration(
|
todayDecoration: BoxDecoration(
|
||||||
border: Border.all(
|
border: Border.all(color: appTheme.blueA400, width: 2),
|
||||||
color: appTheme.blueA400,
|
|
||||||
width: 2,
|
|
||||||
),
|
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
shape: BoxShape.circle,
|
shape: BoxShape.circle,
|
||||||
),
|
),
|
||||||
@@ -152,10 +116,7 @@ class _CalendarWidgetState extends State<CalendarWidget> {
|
|||||||
child: Container(
|
child: Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
padding: const EdgeInsets.only(top: 8, bottom: 16),
|
padding: const EdgeInsets.only(top: 8, bottom: 16),
|
||||||
child: Icon(
|
child: Icon(_calendarFormat == CalendarFormat.month ? Icons.keyboard_arrow_up_rounded : Icons.keyboard_arrow_down_rounded, color: Colors.grey.shade600),
|
||||||
_calendarFormat == CalendarFormat.month ? Icons.keyboard_arrow_up_rounded : Icons.keyboard_arrow_down_rounded,
|
|
||||||
color: Colors.grey.shade600,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import 'dart:developer';
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
|
|||||||
Reference in New Issue
Block a user