refactor(diary) Prepared front-end methods for API intergration

This commit is contained in:
2024-02-21 12:18:25 +03:00
parent 6d04d1a688
commit 65c465ab9d
5 changed files with 103 additions and 271 deletions

View File

@@ -69,37 +69,42 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
// Если текущее состояние уже загружено, обновляем его
var currentState = state as DiaryEditLoadedState;
emit((currentState).copyWith(
wakeupExpanded: currentState.wakeupExpanded,
moodExpanded: currentState.moodExpanded,
wakeupController: currentState.wakeupController,
retireController: currentState.retireController,
commentController: currentState.commentController,
mealTimeController: currentState.mealTimeController,
productNameController: currentState.productNameController,
selectedSatiety: currentState.selectedSatiety,
selectedMood: currentState.selectedMood,
diaryDate: currentState.diaryDate,
diaryId: currentState.diaryId,
productQuantityController:
currentState.productQuantityController,
));
wakeupExpanded: currentState.wakeupExpanded,
moodExpanded: currentState.moodExpanded,
token: currentState.token,
meals: currentState.meals,
wakeupController: currentState.wakeupController,
retireController: currentState.retireController,
commentController: currentState.commentController,
mealTimeController: currentState.mealTimeController,
productNameController: currentState.productNameController,
selectedSatiety: currentState.selectedSatiety,
selectedMood: currentState.selectedMood,
diaryDate: currentState.diaryDate,
diaryId: currentState.diaryId,
productQuantityController:
currentState.productQuantityController,
diaryEditModelObj: currentState.diaryEditModelObj));
} else {
// Если текущее состояние - начальное, создаем новое загруженное состояние
emit(DiaryEditLoadedState(
wakeupExpanded: true,
moodExpanded: true,
wakeupController: toTime(diary['wakeup']),
retireController: toTime(diary['retire']),
mealTimeController: TimeOfDay.now(),
selectedSatiety: 3,
selectedMood: 3,
commentController:
TextEditingController(text: diary['comment']),
productNameController: TextEditingController(),
productQuantityController: TextEditingController(),
diaryId: diaryId,
diaryDate: diaryDate,
));
wakeupExpanded: true,
moodExpanded: true,
token: token,
meals: diary['meals'],
wakeupController: toTime(diary['wakeup'] ?? "09:00"),
retireController: toTime(diary['retire'] ?? "23:00"),
mealTimeController: TimeOfDay.now(),
selectedSatiety: 3,
selectedMood: 3,
commentController:
TextEditingController(text: diary['comment']),
productNameController: TextEditingController(),
productQuantityController: TextEditingController(),
diaryId: diaryId,
diaryDate: diaryDate,
diaryEditModelObj: state.diaryEditModelObj
?.copyWith(mealList: fillMealList())));
}
} else {
// Ошибка при декодировании JSON
@@ -149,6 +154,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
emit(updatedState); // Передаем обновленное состояние в emit
currentState.selectedMood = event.selectedElement;
print(currentState.mealTimeController);
}
}
@@ -179,6 +185,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
emit(currentState.copyWith(wakeupController: event.selectedTime));
currentState.wakeupController = event.selectedTime;
print(currentState.wakeupController);
}
}
@@ -189,6 +196,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
emit(currentState.copyWith(retireController: event.selectedTime));
currentState.retireController = event.selectedTime;
print(currentState.retireController);
}
}
@@ -213,6 +221,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
emit(currentState.copyWith(mealTimeController: event.time));
currentState.mealTimeController = event.time;
print(currentState.mealTimeController);
}
}

View File

@@ -16,7 +16,10 @@ class DiaryEditInitialEvent extends DiaryEditEvent {
}
class ChangeSatiety extends DiaryEditEvent {
ChangeSatiety(this.mealId, this.selectedElement);
ChangeSatiety(
this.selectedElement,
this.mealId,
);
final int selectedElement;
final int mealId;
@@ -25,7 +28,10 @@ class ChangeSatiety extends DiaryEditEvent {
}
class ChangeMood extends DiaryEditEvent {
ChangeMood(this.diaryId, this.selectedElement);
ChangeMood(
this.selectedElement,
this.diaryId,
);
final int selectedElement;
final int diaryId;

View File

@@ -21,6 +21,8 @@ class DiaryEditLoadedState extends DiaryEditState {
DiaryEditLoadedState(
{this.diaryEditModelObj,
this.diaryDate,
this.token,
this.meals,
this.wakeupController,
this.retireController,
this.commentController,
@@ -37,6 +39,8 @@ class DiaryEditLoadedState extends DiaryEditState {
DiaryEditModel? diaryEditModelObj;
String? diaryDate;
String? token;
List<dynamic>? meals;
SelectionPopupModel? currentMeal;
TimeOfDay? wakeupController;
TimeOfDay? retireController;
@@ -53,6 +57,7 @@ class DiaryEditLoadedState extends DiaryEditState {
List<Object?> get props => [
diaryEditModelObj,
diaryDate,
token,
wakeupController,
retireController,
mealTimeController,
@@ -70,6 +75,8 @@ class DiaryEditLoadedState extends DiaryEditState {
DiaryEditModel? diaryEditModelObj,
SelectionPopupModel? currentMeal,
String? diaryDate,
String? token,
List<dynamic>? meals,
TimeOfDay? wakeupController,
TimeOfDay? retireController,
TimeOfDay? mealTimeController,
@@ -85,6 +92,8 @@ class DiaryEditLoadedState extends DiaryEditState {
return DiaryEditLoadedState(
diaryEditModelObj: diaryEditModelObj ?? this.diaryEditModelObj,
diaryDate: diaryDate ?? this.diaryDate,
token: token ?? this.token,
meals: meals ?? this.meals,
wakeupController: wakeupController ?? this.wakeupController,
retireController: retireController ?? this.retireController,
mealTimeController: mealTimeController ?? this.mealTimeController,