diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart index 3c103e80..1133d779 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart @@ -95,11 +95,13 @@ class DiaryEditBloc extends Bloc { moodExpanded: true, token: token, meals: diary['meals'], + portions: diary['meals'][0]['portions'], wakeupController: toTime(diary['wakeup'] ?? "09:00"), retireController: toTime(diary['retire'] ?? "23:00"), - mealTimeController: TimeOfDay.now(), - selectedSatiety: 3, - selectedMood: 3, + mealTimeController: + toTime(diary['meals'][0]['time'] ?? "10:00"), + selectedSatiety: diary['meals'][0]['satiety'], + selectedMood: diary['meals'][0]['mood'], commentController: TextEditingController(text: diary['comment']), productNameController: TextEditingController(), @@ -231,11 +233,11 @@ class DiaryEditBloc extends Bloc { FutureOr _changeMeal(ChangeMeal event, Emitter emit) { if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; - + int? id = event.value.id; emit(currentState.copyWith( currentMeal: event.value, mealTimeController: - toTime(event.meals?[event.value.id ?? 0]['time'] ?? "09:00"), + toTime(event.meals?[event.value.id ?? 0]['time'] ?? "1$id:00"), selectedMood: event.meals?[event.value.id ?? 0]['mood'], selectedSatiety: event.meals?[event.value.id ?? 0]['satiety'])); currentState.currentMeal = event.value; diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart index 6485475d..4ba46d61 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart @@ -23,6 +23,7 @@ class DiaryEditLoadedState extends DiaryEditState { this.diaryDate, this.token, this.meals, + this.portions, this.wakeupController, this.retireController, this.commentController, @@ -41,6 +42,7 @@ class DiaryEditLoadedState extends DiaryEditState { String? diaryDate; String? token; List? meals; + List? portions; SelectionPopupModel? currentMeal; TimeOfDay? wakeupController; TimeOfDay? retireController; @@ -58,6 +60,7 @@ class DiaryEditLoadedState extends DiaryEditState { diaryEditModelObj, diaryDate, token, + meals, wakeupController, retireController, mealTimeController, @@ -77,6 +80,7 @@ class DiaryEditLoadedState extends DiaryEditState { String? diaryDate, String? token, List? meals, + List? portions, TimeOfDay? wakeupController, TimeOfDay? retireController, TimeOfDay? mealTimeController, @@ -94,6 +98,7 @@ class DiaryEditLoadedState extends DiaryEditState { diaryDate: diaryDate ?? this.diaryDate, token: token ?? this.token, meals: meals ?? this.meals, + portions: portions ?? this.portions, wakeupController: wakeupController ?? this.wakeupController, retireController: retireController ?? this.retireController, mealTimeController: mealTimeController ?? this.mealTimeController, diff --git a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart index 87d08ed8..c1813419 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -268,6 +268,7 @@ class DiaryEditScreen extends StatelessWidget { horizontal: 10.h, vertical: 9.v, ), + defaultValue: diaryEditModelObj?.mealList[0], onChanged: (value) { context.read().add( ChangeMeal(meals: state.meals, value: value)); @@ -308,7 +309,9 @@ class DiaryEditScreen extends StatelessWidget { SizedBox(height: 30.v), _buildAddProduct(context), SizedBox(height: 30.v), - _buildProduct(context), + ...state.portions! + .map((portion) => _buildProduct(context, portion)) + .toList(), SizedBox(height: 30.v), _buildAddPhoto(context), SizedBox(height: 30.v), @@ -392,7 +395,7 @@ class DiaryEditScreen extends StatelessWidget { )); } - _buildProduct(BuildContext context) { + _buildProduct(BuildContext context, Map portion) { return Container( margin: EdgeInsets.symmetric(horizontal: 10.h), padding: EdgeInsets.symmetric( @@ -412,7 +415,7 @@ class DiaryEditScreen extends StatelessWidget { top: 5.v, ), child: Text( - "Сырный суп", + portion['name'], style: CustomTextStyles.titleMedium16, ), ), @@ -423,7 +426,7 @@ class DiaryEditScreen extends StatelessWidget { bottom: 3.v, ), child: Text( - "15гр", + portion['quantity'] + portion['portion'], ), ), Spacer(), diff --git a/lib/widgets/custom_edit_drop_down.dart b/lib/widgets/custom_edit_drop_down.dart index 67a2a1f9..59c58593 100644 --- a/lib/widgets/custom_edit_drop_down.dart +++ b/lib/widgets/custom_edit_drop_down.dart @@ -23,6 +23,7 @@ class CustomDropDown extends StatelessWidget { this.filled = true, this.validator, this.onChanged, + this.defaultValue, }) : super( key: key, ); @@ -61,6 +62,8 @@ class CustomDropDown extends StatelessWidget { final bool? filled; + final SelectionPopupModel? defaultValue; + final FormFieldValidator? validator; final Function(SelectionPopupModel)? onChanged; @@ -94,6 +97,7 @@ class CustomDropDown extends StatelessWidget { }).toList(), decoration: decoration, validator: validator, + value: defaultValue, onChanged: (value) { onChanged!(value!); },