forked from eatvio/eatvio_app
feat(diary): More work on API methods
This commit is contained in:
@@ -90,7 +90,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
// Если текущее состояние - начальное, создаем новое загруженное состояние
|
||||
emit(DiaryEditLoadedState(
|
||||
currentMeal: SelectionPopupModel(
|
||||
id: 0, title: "Прием пищи 1", isSelected: true),
|
||||
id: 1, title: "Прием пищи 1", isSelected: true),
|
||||
wakeupExpanded: true,
|
||||
moodExpanded: true,
|
||||
token: token,
|
||||
@@ -208,11 +208,9 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
int diaryID,
|
||||
) async {
|
||||
String url =
|
||||
dotenv.env['SERVER_ROOT']! + '/$diaryID/meal/$mealID/mood/fill';
|
||||
dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/meal/$mealID/fill';
|
||||
final credentials = {
|
||||
'mood': selectedMood,
|
||||
'meal_id': mealID,
|
||||
'diary_id': diaryID,
|
||||
};
|
||||
|
||||
var response = await http.post(Uri.parse(url),
|
||||
@@ -248,10 +246,9 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
TimeOfDay wakeup,
|
||||
int diaryID,
|
||||
) async {
|
||||
String url = dotenv.env['SERVER_ROOT']! + '/diary/???';
|
||||
String url = dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/wakeUp/fill';
|
||||
final credentials = {
|
||||
'wakeup': wakeup,
|
||||
'diary_id': diaryID,
|
||||
};
|
||||
|
||||
var response = await http.post(Uri.parse(url),
|
||||
@@ -312,8 +309,8 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
currentState.currentMeal?.id, currentState.diaryId);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
currentState.retireController = event.time;
|
||||
emit(currentState); // Передаем обновленное состояние в emit
|
||||
updatedState.mealTimeController = event.time;
|
||||
emit(updatedState); // Передаем обновленное состояние в emit
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -393,34 +390,32 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
// Отправляем данные по HTTP маршруту и ждем ответ
|
||||
var response = await sendPortionData(
|
||||
currentState.token,
|
||||
event.name,
|
||||
event.portion,
|
||||
event.quantity,
|
||||
currentState.productNameController?.text,
|
||||
'pcs',
|
||||
int.parse(currentState.productQuantityController!.text),
|
||||
currentState.currentMeal!.id,
|
||||
currentState.diaryId);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
emit(currentState); // Передаем обновленное состояние в emit
|
||||
emit(updatedState); // Передаем обновленное состояние в emit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<http.Response> sendPortionData(
|
||||
String? token,
|
||||
String name,
|
||||
String? name,
|
||||
String portion,
|
||||
int quantity,
|
||||
int? quantity,
|
||||
int? mealID,
|
||||
int diaryID,
|
||||
) async {
|
||||
String url =
|
||||
dotenv.env['SERVER_ROOT']! + '/$diaryID/meal/$mealID/portions/create';
|
||||
String url = dotenv.env['SERVER_ROOT']! +
|
||||
'diary/$diaryID/meal/$mealID/portions/create';
|
||||
final credentials = {
|
||||
'name': name,
|
||||
'product_name': name,
|
||||
'portion': portion,
|
||||
'quantity': quantity,
|
||||
'meal_id': mealID,
|
||||
'diary_id': diaryID,
|
||||
};
|
||||
|
||||
var response = await http.post(Uri.parse(url),
|
||||
@@ -502,12 +497,12 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
|
||||
List<SelectionPopupModel> fillMealList() {
|
||||
return [
|
||||
SelectionPopupModel(id: 0, title: "Прием пищи 1", isSelected: true),
|
||||
SelectionPopupModel(id: 1, title: "Прием пищи 2"),
|
||||
SelectionPopupModel(id: 2, title: "Прием пищи 3"),
|
||||
SelectionPopupModel(id: 3, title: "Прием пищи 4"),
|
||||
SelectionPopupModel(id: 4, title: "Прием пищи 5"),
|
||||
SelectionPopupModel(id: 5, title: "Прием пищи 6"),
|
||||
SelectionPopupModel(id: 1, title: "Прием пищи 1", isSelected: true),
|
||||
SelectionPopupModel(id: 2, title: "Прием пищи 2"),
|
||||
SelectionPopupModel(id: 3, title: "Прием пищи 3"),
|
||||
SelectionPopupModel(id: 4, title: "Прием пищи 4"),
|
||||
SelectionPopupModel(id: 5, title: "Прием пищи 5"),
|
||||
SelectionPopupModel(id: 6, title: "Прием пищи 6"),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,12 +79,9 @@ class ToggleWakeupExpandedEvent extends DiaryEditEvent {
|
||||
}
|
||||
|
||||
class AddPortionEvent extends DiaryEditEvent {
|
||||
AddPortionEvent(this.name, this.quantity, this.portion);
|
||||
final String name;
|
||||
final int quantity;
|
||||
final String portion;
|
||||
AddPortionEvent();
|
||||
@override
|
||||
List<Object> get props => [name, quantity, portion];
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class RemovePortionEvent extends DiaryEditEvent {
|
||||
|
||||
@@ -144,11 +144,14 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
/// Section Widget
|
||||
Widget _buildAddProduct(BuildContext context) {
|
||||
Widget _buildAddProduct(BuildContext context, DiaryEditLoadedState state) {
|
||||
return CustomOutlinedButton(
|
||||
text: "Добавить продукт",
|
||||
margin: EdgeInsets.symmetric(horizontal: 10.h),
|
||||
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||
onPressed: () {
|
||||
context.read<DiaryEditBloc>().add(AddPortionEvent());
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -311,7 +314,7 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
SizedBox(height: 30.v),
|
||||
_buildAddProduct(context),
|
||||
_buildAddProduct(context, state),
|
||||
SizedBox(height: 30.v),
|
||||
...state.portions!
|
||||
.map((portion) => _buildProduct(context, portion))
|
||||
|
||||
Reference in New Issue
Block a user