forked from eatvio/eatvio_app
feat(diary) Default Meal time values and Portions dynamic display for each meal
This commit is contained in:
@@ -95,11 +95,13 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
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<DiaryEditEvent, DiaryEditState> {
|
||||
FutureOr<void> _changeMeal(ChangeMeal event, Emitter<DiaryEditState> 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;
|
||||
|
||||
@@ -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<dynamic>? meals;
|
||||
List<dynamic>? 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<dynamic>? meals,
|
||||
List<dynamic>? 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,
|
||||
|
||||
@@ -268,6 +268,7 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
horizontal: 10.h,
|
||||
vertical: 9.v,
|
||||
),
|
||||
defaultValue: diaryEditModelObj?.mealList[0],
|
||||
onChanged: (value) {
|
||||
context.read<DiaryEditBloc>().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<String, dynamic> 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(),
|
||||
|
||||
@@ -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<SelectionPopupModel>? validator;
|
||||
|
||||
final Function(SelectionPopupModel)? onChanged;
|
||||
@@ -94,6 +97,7 @@ class CustomDropDown extends StatelessWidget {
|
||||
}).toList(),
|
||||
decoration: decoration,
|
||||
validator: validator,
|
||||
value: defaultValue,
|
||||
onChanged: (value) {
|
||||
onChanged!(value!);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user