feat(diary) Dynamic current meal display

This commit is contained in:
2024-02-21 14:34:04 +03:00
parent 65c465ab9d
commit becf515acc
3 changed files with 16 additions and 11 deletions

View File

@@ -40,7 +40,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
) async {
try {
final token =
"1|laravel_sanctum_8qeVUwDzs440SoG1pJFdSFtYWjJhZfEQXqStVkFPea8d4092";
"laravel_sanctum_RzcUqh1zBYFCIG5tBFvfxyvA1NER9fMQiKlqlJFYeb618e64";
final response = await http.get(
Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/index'),
headers: {
@@ -61,7 +61,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
);
final diary = jsonDecode(response.body)['diary'];
if (diary is Map<String, dynamic>) {
print(diary);
print(diary['meals'][1].runtimeType);
final String diaryDate =
diary['date'] ?? DateTime.now().toString();
// Продолжайте обработку данных дневника
@@ -69,6 +69,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
// Если текущее состояние уже загружено, обновляем его
var currentState = state as DiaryEditLoadedState;
emit((currentState).copyWith(
currentMeal: currentState.currentMeal,
wakeupExpanded: currentState.wakeupExpanded,
moodExpanded: currentState.moodExpanded,
token: currentState.token,
@@ -88,6 +89,8 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
} else {
// Если текущее состояние - начальное, создаем новое загруженное состояние
emit(DiaryEditLoadedState(
currentMeal: SelectionPopupModel(
id: 0, title: "Прием пищи 1", isSelected: true),
wakeupExpanded: true,
moodExpanded: true,
token: token,
@@ -229,7 +232,12 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
if (state is DiaryEditLoadedState) {
var currentState = state as DiaryEditLoadedState;
emit(currentState.copyWith(currentMeal: event.value));
emit(currentState.copyWith(
currentMeal: event.value,
mealTimeController:
toTime(event.meals?[event.value.id ?? 0]['time'] ?? "09:00"),
selectedMood: event.meals?[event.value.id ?? 0]['mood'],
selectedSatiety: event.meals?[event.value.id ?? 0]['satiety']));
currentState.currentMeal = event.value;
}
}

View File

@@ -110,12 +110,10 @@ class UploadImages extends DiaryEditEvent {
}
class ChangeMeal extends DiaryEditEvent {
ChangeMeal({required this.value});
ChangeMeal({required this.value, required this.meals});
SelectionPopupModel value;
List<dynamic>? meals;
@override
List<Object?> get props => [
value,
];
List<Object?> get props => [value, meals];
}

View File

@@ -269,9 +269,8 @@ class DiaryEditScreen extends StatelessWidget {
vertical: 9.v,
),
onChanged: (value) {
context
.read<DiaryEditBloc>()
.add(ChangeMeal(value: value));
context.read<DiaryEditBloc>().add(
ChangeMeal(meals: state.meals, value: value));
},
);
})),