forked from eatvio/eatvio_app
feat(diary): Photo added to state manager
This commit is contained in:
@@ -79,6 +79,8 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
moderationExpanded: currentState.moderationExpanded,
|
||||
token: currentState.token,
|
||||
meals: currentState.meals,
|
||||
portions: currentState.portions,
|
||||
photos: currentState.photos,
|
||||
wakeupController: currentState.wakeupController,
|
||||
retireController: currentState.retireController,
|
||||
commentController: currentState.commentController,
|
||||
@@ -90,7 +92,6 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
carbsController: currentState.carbsController,
|
||||
selectedSatiety: currentState.selectedSatiety,
|
||||
selectedMood: currentState.selectedMood,
|
||||
portions: currentState.portions,
|
||||
diaryDate: currentState.diaryDate,
|
||||
diaryId: currentState.diaryId,
|
||||
productQuantityController:
|
||||
@@ -108,6 +109,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
token: token,
|
||||
meals: diary['meals'],
|
||||
portions: diary['meals'][0]['portions'],
|
||||
photos: diary['meals'][0]['photos'],
|
||||
wakeupController: toTime(diary['wakeup'] ?? "09:00"),
|
||||
retireController: toTime(diary['retire'] ?? "23:00"),
|
||||
mealTimeController:
|
||||
@@ -183,7 +185,6 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
final diary = jsonDecode(diaryResponse.body)['diary'];
|
||||
|
||||
if (diary is Map<String, dynamic>) {
|
||||
print(diary);
|
||||
final String diaryDate = diary['date'] ?? DateTime.now().toString();
|
||||
// Продолжайте обработку данных дневника
|
||||
// Если текущее состояние - начальное, создаем новое загруженное состояние
|
||||
@@ -197,6 +198,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
token: token,
|
||||
meals: diary['meals'],
|
||||
portions: diary['meals'][0]['portions'],
|
||||
photos: diary['meals'][0]['photos'],
|
||||
wakeupController: toTime(diary['wakeup'] ?? "09:00"),
|
||||
retireController: toTime(diary['retire'] ?? "23:00"),
|
||||
mealTimeController:
|
||||
@@ -216,6 +218,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
autocompleteList: [],
|
||||
diaryEditModelObj: state.diaryEditModelObj
|
||||
?.copyWith(mealList: fillMealList()))));
|
||||
|
||||
print("Updated");
|
||||
} catch (e) {
|
||||
print("Ошибка при создании нового состояния $e");
|
||||
@@ -333,9 +336,8 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
currentState.copyWith(wakeupController: event.selectedTime);
|
||||
print("Wakeup time changed to ${event.selectedTime}");
|
||||
emit(updatedState); // Передаем обновленное состояние в emit
|
||||
} else {
|
||||
} else
|
||||
print("Wakeup time change error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,17 +367,17 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
final wakeupString =
|
||||
formatter.format(DateTime(2022, 1, 1, wakeup.hour, wakeup.minute));
|
||||
final Map<String, dynamic> credentials = {
|
||||
'wakeup': wakeupString,
|
||||
'wakeUp': wakeupString,
|
||||
};
|
||||
var response = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
body: json.encode(credentials),
|
||||
encoding: utf8,
|
||||
);
|
||||
|
||||
var response = await http.post(Uri.parse(url),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
body: json.encode(credentials),
|
||||
encoding: utf8);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -446,6 +448,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
DiaryEditLoadedState updatedState = currentState.copyWith(
|
||||
currentMeal: event.value,
|
||||
portions: meal['portions'],
|
||||
photos: meal['photos'],
|
||||
mealTimeController: toTime(meal['time'] ?? "1$id:00"),
|
||||
selectedMood: meal['mood'],
|
||||
selectedSatiety: meal['satiety']);
|
||||
@@ -655,13 +658,8 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
if (state is DiaryEditLoadedState) {
|
||||
var currentState = state as DiaryEditLoadedState;
|
||||
|
||||
String imageUrl = await uploadImageToServer(
|
||||
event.image.path,
|
||||
currentState.diaryId,
|
||||
currentState.currentMeal!.id!,
|
||||
currentState.token);
|
||||
|
||||
print(imageUrl);
|
||||
await uploadImageToServer(event.image.path, currentState.diaryId,
|
||||
currentState.currentMeal!.id!, currentState.token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -673,7 +671,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
var request = http.MultipartRequest('POST', Uri.parse(url));
|
||||
request.headers['Authorization'] = 'Bearer $token';
|
||||
|
||||
request.files.add(await http.MultipartFile.fromPath('image', imagePath));
|
||||
request.files.add(await http.MultipartFile.fromPath('photo', imagePath));
|
||||
|
||||
var client = http.Client();
|
||||
var streamedResponse = await client.send(request);
|
||||
@@ -681,6 +679,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
if (streamedResponse.statusCode == 200) {
|
||||
var response = await http.Response.fromStream(streamedResponse);
|
||||
var imageUrl = response.body;
|
||||
print('Image successfully uploaded');
|
||||
return imageUrl;
|
||||
} else {
|
||||
throw Exception(
|
||||
|
||||
@@ -24,6 +24,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
this.token,
|
||||
this.meals,
|
||||
this.portions,
|
||||
this.photos,
|
||||
this.autocompleteList,
|
||||
this.wakeupController,
|
||||
this.retireController,
|
||||
@@ -49,6 +50,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
String? token;
|
||||
List<dynamic>? meals;
|
||||
List<dynamic>? portions;
|
||||
List<dynamic>? photos;
|
||||
List<dynamic>? autocompleteList;
|
||||
SelectionPopupModel? currentMeal;
|
||||
TimeOfDay? wakeupController;
|
||||
@@ -73,6 +75,8 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
diaryDate,
|
||||
token,
|
||||
meals,
|
||||
portions,
|
||||
photos,
|
||||
autocompleteList,
|
||||
wakeupController,
|
||||
retireController,
|
||||
@@ -99,6 +103,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
String? token,
|
||||
List<dynamic>? meals,
|
||||
List<dynamic>? portions,
|
||||
List<dynamic>? photos,
|
||||
List<dynamic>? autocompleteList,
|
||||
TimeOfDay? wakeupController,
|
||||
TimeOfDay? retireController,
|
||||
|
||||
Reference in New Issue
Block a user