forked from eatvio/eatvio_app
feat(diary): Added portion change (pcs gr)
This commit is contained in:
@@ -133,4 +133,6 @@ final Map<String, String> ru = {
|
||||
"admin": "Админ",
|
||||
"diary": "Дневник",
|
||||
"save": "Сохранить",
|
||||
"pcs": "порций",
|
||||
"gr": "гр",
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
on<ChangeMood>(_changeMood); // пользователь нажимает на шкалу настроения
|
||||
on<ChangeMealTime>(_changeMealTime); // пользовательяет времяа пиши
|
||||
on<ChangeMeal>(_changeMeal);
|
||||
on<ChangePortion>(_changePortion);
|
||||
on<WakeupEvent>(_changeWakeup); // пользователь выбирает время пробуждения
|
||||
on<RetireEvent>(_changeRetire); // пользователь выбирает время отхода ко сну
|
||||
on<ToggleMoodExpandedEvent>(_toggleMood);
|
||||
@@ -103,6 +104,8 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
emit(DiaryEditLoadedState(
|
||||
currentMeal: SelectionPopupModel(
|
||||
id: 1, title: "Прием пищи 1", isSelected: true),
|
||||
portionController: SelectionPopupModel(
|
||||
id: 0, title: "порций", isSelected: true),
|
||||
wakeupExpanded: true,
|
||||
moodExpanded: true,
|
||||
moderationExpanded: false,
|
||||
@@ -127,8 +130,9 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
diaryId: diaryId,
|
||||
diaryDate: diaryDate,
|
||||
autocompleteList: [],
|
||||
diaryEditModelObj: state.diaryEditModelObj
|
||||
?.copyWith(mealList: fillMealList())));
|
||||
diaryEditModelObj: state.diaryEditModelObj?.copyWith(
|
||||
mealList: fillMealList(),
|
||||
portionList: fillPortions())));
|
||||
}
|
||||
} else {
|
||||
// Ошибка при декодировании JSON
|
||||
@@ -192,6 +196,8 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
await Future(() => emit(DiaryEditLoadedState(
|
||||
currentMeal: SelectionPopupModel(
|
||||
id: 1, title: "Прием пищи 1", isSelected: true),
|
||||
portionController: SelectionPopupModel(
|
||||
id: 0, title: "порций", isSelected: true),
|
||||
wakeupExpanded: true,
|
||||
moodExpanded: true,
|
||||
moderationExpanded: false,
|
||||
@@ -216,8 +222,8 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
diaryId: diaryId,
|
||||
diaryDate: diaryDate,
|
||||
autocompleteList: [],
|
||||
diaryEditModelObj: state.diaryEditModelObj
|
||||
?.copyWith(mealList: fillMealList()))));
|
||||
diaryEditModelObj: state.diaryEditModelObj?.copyWith(
|
||||
mealList: fillMealList(), portionList: fillPortions()))));
|
||||
|
||||
print("Updated");
|
||||
} catch (e) {
|
||||
@@ -456,6 +462,18 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _changePortion(
|
||||
ChangePortion event, Emitter<DiaryEditState> emit) {
|
||||
if (state is DiaryEditLoadedState) {
|
||||
var currentState = state as DiaryEditLoadedState;
|
||||
DiaryEditLoadedState updatedState = currentState.copyWith(
|
||||
portionController: event.value,
|
||||
);
|
||||
print(updatedState.portionController?.title);
|
||||
emit(updatedState);
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _toggleMood(
|
||||
ToggleMoodExpandedEvent event, Emitter<DiaryEditState> emit) {
|
||||
if (state is DiaryEditLoadedState) {
|
||||
@@ -484,7 +502,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
var response = await sendPortionData(
|
||||
currentState.token,
|
||||
currentState.productNameController?.text,
|
||||
'pcs',
|
||||
currentState.portionController?.id == 0 ? 'pcs' : 'gr',
|
||||
int.parse(currentState.productQuantityController!.text),
|
||||
currentState.currentMeal!.id,
|
||||
currentState.diaryId,
|
||||
@@ -803,4 +821,11 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
SelectionPopupModel(id: 6, title: "Прием пищи 6"),
|
||||
];
|
||||
}
|
||||
|
||||
List<SelectionPopupModel> fillPortions() {
|
||||
return [
|
||||
SelectionPopupModel(id: 0, title: "порций", isSelected: true),
|
||||
SelectionPopupModel(id: 1, title: "грамм"),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +114,14 @@ class ChangeMeal extends DiaryEditEvent {
|
||||
List<Object?> get props => [value, meals];
|
||||
}
|
||||
|
||||
class ChangePortion extends DiaryEditEvent {
|
||||
ChangePortion({required this.value});
|
||||
|
||||
SelectionPopupModel value;
|
||||
@override
|
||||
List<Object?> get props => [value];
|
||||
}
|
||||
|
||||
class FinishDay extends DiaryEditEvent {
|
||||
FinishDay();
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
this.retireController,
|
||||
this.commentController,
|
||||
this.mealTimeController,
|
||||
this.portionController,
|
||||
this.productNameController,
|
||||
this.productQuantityController,
|
||||
this.selectedMood,
|
||||
@@ -53,6 +54,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
List<dynamic>? photos;
|
||||
List<dynamic>? autocompleteList;
|
||||
SelectionPopupModel? currentMeal;
|
||||
SelectionPopupModel? portionController;
|
||||
TimeOfDay? wakeupController;
|
||||
TimeOfDay? retireController;
|
||||
TimeOfDay? mealTimeController;
|
||||
@@ -84,6 +86,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
commentController,
|
||||
productNameController,
|
||||
productQuantityController,
|
||||
portionController,
|
||||
caloriesController,
|
||||
fatsController,
|
||||
proteinsController,
|
||||
@@ -99,6 +102,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
DiaryEditLoadedState copyWith({
|
||||
DiaryEditModel? diaryEditModelObj,
|
||||
SelectionPopupModel? currentMeal,
|
||||
SelectionPopupModel? portionController,
|
||||
String? diaryDate,
|
||||
String? token,
|
||||
List<dynamic>? meals,
|
||||
@@ -133,6 +137,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
retireController: retireController ?? this.retireController,
|
||||
mealTimeController: mealTimeController ?? this.mealTimeController,
|
||||
commentController: commentController ?? this.commentController,
|
||||
portionController: portionController ?? this.portionController,
|
||||
productNameController:
|
||||
productNameController ?? this.productNameController,
|
||||
productQuantityController:
|
||||
|
||||
@@ -365,25 +365,36 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
SizedBox(height: 20.v),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10.h),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
CustomTextFormField(
|
||||
width: 146.h,
|
||||
hintText: "Кол-во",
|
||||
textInputAction: TextInputAction.done,
|
||||
focusNode: focusNodeQuantity,
|
||||
controller: state.productQuantityController,
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: <TextInputFormatter>[digitsOnly],
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(right: 30.h),
|
||||
child: Text(
|
||||
"порций",
|
||||
style: CustomTextStyles.bodyMediumBlack900,
|
||||
)),
|
||||
],
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
CustomTextFormField(
|
||||
width: 150.h,
|
||||
hintText: "Кол-во",
|
||||
textInputAction: TextInputAction.done,
|
||||
focusNode: focusNodeQuantity,
|
||||
controller: state.productQuantityController,
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: <TextInputFormatter>[digitsOnly],
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 30.h),
|
||||
child: BlocSelector<DiaryEditBloc, DiaryEditState,
|
||||
DiaryEditModel?>(
|
||||
selector: (state) => state.diaryEditModelObj,
|
||||
builder: (context, diaryEditModelObj) {
|
||||
return CustomDropDown(
|
||||
items: diaryEditModelObj?.portionList,
|
||||
defaultValue: diaryEditModelObj?.portionList?[0],
|
||||
onChanged: changePortion(context, state),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: 30.v),
|
||||
@@ -583,6 +594,12 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
};
|
||||
}
|
||||
|
||||
changePortion(BuildContext context, DiaryEditLoadedState state) {
|
||||
return (value) {
|
||||
context.read<DiaryEditBloc>().add(ChangePortion(value: value));
|
||||
};
|
||||
}
|
||||
|
||||
_buildProduct(BuildContext context, Map<String, dynamic> portion) {
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 10.h),
|
||||
@@ -617,7 +634,7 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
child: Text(
|
||||
portion['quantity'].toString() +
|
||||
' ' +
|
||||
portion['portion'].toString(),
|
||||
portion['portion'].toString().tr,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
|
||||
@@ -6,17 +6,20 @@ import 'package:eatvio_app/data/models/selectionPopupModel/selection_popup_model
|
||||
/// This class defines the variables used in the [k0_page],
|
||||
/// and is typically used to hold data that is passed between different parts of the application.
|
||||
class DiaryEditModel extends Equatable {
|
||||
DiaryEditModel({this.mealList = const []});
|
||||
DiaryEditModel({this.mealList = const [], this.portionList = const []});
|
||||
|
||||
List<SelectionPopupModel> mealList;
|
||||
List<SelectionPopupModel>? portionList;
|
||||
DiaryEditModel copyWith({
|
||||
List<SelectionPopupModel>? mealList,
|
||||
List<SelectionPopupModel>? portionList,
|
||||
}) {
|
||||
return DiaryEditModel(
|
||||
mealList: mealList ?? this.mealList,
|
||||
portionList: portionList ?? this.portionList,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [mealList];
|
||||
List<Object?> get props => [mealList, portionList];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user