forked from eatvio/eatvio_app
Merge pull request 'diary' (#24) from maxxkim/eatvio_app:diary into main
Reviewed-on: eatvio/eatvio_app#24 Reviewed-by: apoloz <anatoliy.poloz@gmail.com>
This commit is contained in:
@@ -133,4 +133,6 @@ final Map<String, String> ru = {
|
||||
"admin": "Админ",
|
||||
"diary": "Дневник",
|
||||
"save": "Сохранить",
|
||||
"pcs": "порций",
|
||||
"gr": "гр",
|
||||
};
|
||||
|
||||
@@ -71,6 +71,12 @@ class AuthScreen extends StatelessWidget {
|
||||
EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v),
|
||||
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||
onPressed: onTapDiaryTest(context)),
|
||||
NextStepButton(
|
||||
text: "Тест профиля".toUpperCase(),
|
||||
margin:
|
||||
EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v),
|
||||
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||
onPressed: onTapProfileTest(context)),
|
||||
BlocBuilder<AuthBloc, AuthState>(builder: (context, state) {
|
||||
return NextStepButton(
|
||||
text: "authentificate".tr.toUpperCase(),
|
||||
@@ -156,6 +162,12 @@ class AuthScreen extends StatelessWidget {
|
||||
};
|
||||
}
|
||||
|
||||
onTapProfileTest(BuildContext context) {
|
||||
return () {
|
||||
Navigator.pushNamed(context, AppRoutes.mySettings);
|
||||
};
|
||||
}
|
||||
|
||||
onTapNoAccount(BuildContext context) {
|
||||
return () {
|
||||
Navigator.pushNamed(context, AppRoutes.languageSelectScreen);
|
||||
|
||||
@@ -20,13 +20,15 @@ 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);
|
||||
on<ToggleWakeupExpandedEvent>(_toggleWakeup);
|
||||
on<AddPortionEvent>(_addPortion); //пользователь нажимает "Добавить продукт"
|
||||
on<RemovePortionEvent>(
|
||||
_removePortion); // пользователь нажимает на крестик около продукта
|
||||
on<RemovePortionEvent>(_removePortion);
|
||||
on<RemoveImageEvent>(
|
||||
_removeImage); // пользователь нажимает на крестик около продукта
|
||||
on<UploadImages>(_uploadImages); //пользователь нажимает "Добавить фото"
|
||||
on<AddComment>(_addComment); //пользователь нажимает "Добавить комментарий"
|
||||
on<ProductInput>(
|
||||
@@ -68,67 +70,97 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
if (diary is Map<String, dynamic>) {
|
||||
final String diaryDate =
|
||||
diary['date'] ?? DateTime.now().toString();
|
||||
// Продолжайте обработку данных дневника
|
||||
if (state is DiaryEditLoadedState) {
|
||||
// Если текущее состояние уже загружено, обновляем его
|
||||
var currentState = state as DiaryEditLoadedState;
|
||||
emit((currentState).copyWith(
|
||||
currentMeal: currentState.currentMeal,
|
||||
wakeupExpanded: currentState.wakeupExpanded,
|
||||
moodExpanded: currentState.moodExpanded,
|
||||
moderationExpanded: currentState.moderationExpanded,
|
||||
token: currentState.token,
|
||||
meals: currentState.meals,
|
||||
portions: currentState.portions,
|
||||
photos: currentState.photos,
|
||||
wakeupController: currentState.wakeupController,
|
||||
retireController: currentState.retireController,
|
||||
commentController: currentState.commentController,
|
||||
mealTimeController: currentState.mealTimeController,
|
||||
productNameController: currentState.productNameController,
|
||||
caloriesController: currentState.caloriesController,
|
||||
proteinsController: currentState.proteinsController,
|
||||
fatsController: currentState.fatsController,
|
||||
carbsController: currentState.carbsController,
|
||||
selectedSatiety: currentState.selectedSatiety,
|
||||
selectedMood: currentState.selectedMood,
|
||||
diaryDate: currentState.diaryDate,
|
||||
diaryId: currentState.diaryId,
|
||||
productQuantityController:
|
||||
currentState.productQuantityController,
|
||||
autocompleteList: currentState.autocompleteList,
|
||||
diaryEditModelObj: currentState.diaryEditModelObj));
|
||||
final responseChart = await http.get(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! +
|
||||
'/diary/$diaryId/dailyNutritionData/'),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
);
|
||||
if (responseChart.statusCode == 200) {
|
||||
final recommendedChartValues = jsonDecode(
|
||||
responseChart.body)['dailyNutritionRecommendation'];
|
||||
final consumedChartValues =
|
||||
jsonDecode(responseChart.body)['dailyNutritionIntake'];
|
||||
|
||||
if (state is DiaryEditLoadedState) {
|
||||
// Если текущее состояние уже загружено, обновляем его
|
||||
var currentState = state as DiaryEditLoadedState;
|
||||
emit((currentState).copyWith(
|
||||
currentMeal: currentState.currentMeal,
|
||||
wakeupExpanded: currentState.wakeupExpanded,
|
||||
moodExpanded: currentState.moodExpanded,
|
||||
moderationExpanded: currentState.moderationExpanded,
|
||||
token: currentState.token,
|
||||
meals: currentState.meals,
|
||||
portions: currentState.portions,
|
||||
photos: currentState.photos,
|
||||
wakeupController: currentState.wakeupController,
|
||||
retireController: currentState.retireController,
|
||||
commentController: currentState.commentController,
|
||||
mealTimeController: currentState.mealTimeController,
|
||||
productNameController: currentState.productNameController,
|
||||
caloriesController: currentState.caloriesController,
|
||||
proteinsController: currentState.proteinsController,
|
||||
fatsController: currentState.fatsController,
|
||||
carbsController: currentState.carbsController,
|
||||
selectedSatiety: currentState.selectedSatiety,
|
||||
selectedMood: currentState.selectedMood,
|
||||
diaryDate: currentState.diaryDate,
|
||||
diaryId: currentState.diaryId,
|
||||
productQuantityController:
|
||||
currentState.productQuantityController,
|
||||
recommendedChartValues:
|
||||
currentState.recommendedChartValues,
|
||||
consumedChartValues: currentState.consumedChartValues,
|
||||
autocompleteList: currentState.autocompleteList,
|
||||
diaryEditModelObj: currentState.diaryEditModelObj));
|
||||
} else {
|
||||
// Если текущее состояние - начальное, создаем новое загруженное состояние
|
||||
emit(DiaryEditLoadedState(
|
||||
currentMeal: SelectionPopupModel(
|
||||
id: 1, title: "Прием пищи 1", isSelected: true),
|
||||
portionController: SelectionPopupModel(
|
||||
id: 0, title: "порций", isSelected: true),
|
||||
wakeupExpanded: true,
|
||||
moodExpanded: true,
|
||||
moderationExpanded: false,
|
||||
token: token,
|
||||
recommendedChartValues: recommendedChartValues.values
|
||||
.map<int>((value) => value as int)
|
||||
.toList(),
|
||||
consumedChartValues: consumedChartValues.values
|
||||
.map<int>((value) => value as int)
|
||||
.toList() ??
|
||||
[0, 0, 0, 0],
|
||||
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:
|
||||
toTime(diary['meals'][0]['time'] ?? "10:00"),
|
||||
selectedSatiety: diary['meals'][0]['satiety'],
|
||||
selectedMood: diary['meals'][0]['mood'],
|
||||
commentController:
|
||||
TextEditingController(text: diary['comment']),
|
||||
productNameController: TextEditingController(),
|
||||
productQuantityController: TextEditingController(),
|
||||
caloriesController: TextEditingController(),
|
||||
proteinsController: TextEditingController(),
|
||||
fatsController: TextEditingController(),
|
||||
carbsController: TextEditingController(),
|
||||
diaryId: diaryId,
|
||||
diaryDate: diaryDate,
|
||||
autocompleteList: [],
|
||||
diaryEditModelObj: state.diaryEditModelObj?.copyWith(
|
||||
mealList: fillMealList(),
|
||||
portionList: fillPortions())));
|
||||
}
|
||||
} else {
|
||||
// Если текущее состояние - начальное, создаем новое загруженное состояние
|
||||
emit(DiaryEditLoadedState(
|
||||
currentMeal: SelectionPopupModel(
|
||||
id: 1, title: "Прием пищи 1", isSelected: true),
|
||||
wakeupExpanded: true,
|
||||
moodExpanded: true,
|
||||
moderationExpanded: false,
|
||||
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:
|
||||
toTime(diary['meals'][0]['time'] ?? "10:00"),
|
||||
selectedSatiety: diary['meals'][0]['satiety'],
|
||||
selectedMood: diary['meals'][0]['mood'],
|
||||
commentController:
|
||||
TextEditingController(text: diary['comment']),
|
||||
productNameController: TextEditingController(),
|
||||
productQuantityController: TextEditingController(),
|
||||
caloriesController: TextEditingController(),
|
||||
proteinsController: TextEditingController(),
|
||||
fatsController: TextEditingController(),
|
||||
carbsController: TextEditingController(),
|
||||
diaryId: diaryId,
|
||||
diaryDate: diaryDate,
|
||||
autocompleteList: [],
|
||||
diaryEditModelObj: state.diaryEditModelObj
|
||||
?.copyWith(mealList: fillMealList())));
|
||||
emit(DiaryEditErrorState(
|
||||
'Ошибка при декодировании данных КБЖУ'));
|
||||
}
|
||||
} else {
|
||||
// Ошибка при декодировании JSON
|
||||
@@ -186,42 +218,65 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
|
||||
if (diary is Map<String, dynamic>) {
|
||||
final String diaryDate = diary['date'] ?? DateTime.now().toString();
|
||||
// Продолжайте обработку данных дневника
|
||||
// Если текущее состояние - начальное, создаем новое загруженное состояние
|
||||
try {
|
||||
await Future(() => emit(DiaryEditLoadedState(
|
||||
currentMeal: SelectionPopupModel(
|
||||
id: 1, title: "Прием пищи 1", isSelected: true),
|
||||
wakeupExpanded: true,
|
||||
moodExpanded: true,
|
||||
moderationExpanded: false,
|
||||
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:
|
||||
toTime(diary['meals'][0]['time'] ?? "10:00"),
|
||||
selectedSatiety: diary['meals'][0]['satiety'],
|
||||
selectedMood: diary['meals'][0]['mood'],
|
||||
commentController:
|
||||
TextEditingController(text: diary['comment']),
|
||||
productNameController: TextEditingController(),
|
||||
productQuantityController: TextEditingController(),
|
||||
caloriesController: TextEditingController(),
|
||||
proteinsController: TextEditingController(),
|
||||
fatsController: TextEditingController(),
|
||||
carbsController: TextEditingController(),
|
||||
diaryId: diaryId,
|
||||
diaryDate: diaryDate,
|
||||
autocompleteList: [],
|
||||
diaryEditModelObj: state.diaryEditModelObj
|
||||
?.copyWith(mealList: fillMealList()))));
|
||||
final responseChart = await http.get(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! +
|
||||
'/diary/$diaryId/dailyNutritionData/'),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
);
|
||||
if (responseChart.statusCode == 200) {
|
||||
final recommendedChartValues = jsonDecode(
|
||||
responseChart.body)['dailyNutritionRecommendation'];
|
||||
final consumedChartValues =
|
||||
jsonDecode(responseChart.body)['dailyNutritionIntake'];
|
||||
try {
|
||||
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,
|
||||
token: token,
|
||||
recommendedChartValues: recommendedChartValues.values
|
||||
.map<int>((value) => value as int)
|
||||
.toList(),
|
||||
consumedChartValues: consumedChartValues.values
|
||||
.map<int>((value) => value as int)
|
||||
.toList(),
|
||||
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:
|
||||
toTime(diary['meals'][0]['time'] ?? "10:00"),
|
||||
selectedSatiety: diary['meals'][0]['satiety'],
|
||||
selectedMood: diary['meals'][0]['mood'],
|
||||
commentController:
|
||||
TextEditingController(text: diary['comment']),
|
||||
productNameController: TextEditingController(),
|
||||
productQuantityController: TextEditingController(),
|
||||
caloriesController: TextEditingController(),
|
||||
proteinsController: TextEditingController(),
|
||||
fatsController: TextEditingController(),
|
||||
carbsController: TextEditingController(),
|
||||
diaryId: diaryId,
|
||||
diaryDate: diaryDate,
|
||||
autocompleteList: [],
|
||||
diaryEditModelObj: state.diaryEditModelObj?.copyWith(
|
||||
mealList: fillMealList(),
|
||||
portionList: fillPortions()))));
|
||||
|
||||
print("Updated");
|
||||
} catch (e) {
|
||||
print("Ошибка при создании нового состояния $e");
|
||||
print("Updated");
|
||||
} catch (e) {
|
||||
print("Ошибка при создании нового состояния $e");
|
||||
}
|
||||
} else {
|
||||
emit(DiaryEditErrorState('Ошибка при декодировании данных КБЖУ'));
|
||||
}
|
||||
} else {
|
||||
emit(DiaryEditErrorState(
|
||||
@@ -444,6 +499,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
(meal) => meal['type'] == event.value.id,
|
||||
orElse: () => null);
|
||||
|
||||
print(meal);
|
||||
int? id = event.value.id;
|
||||
DiaryEditLoadedState updatedState = currentState.copyWith(
|
||||
currentMeal: event.value,
|
||||
@@ -456,6 +512,17 @@ 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,
|
||||
);
|
||||
emit(updatedState);
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _toggleMood(
|
||||
ToggleMoodExpandedEvent event, Emitter<DiaryEditState> emit) {
|
||||
if (state is DiaryEditLoadedState) {
|
||||
@@ -484,14 +551,12 @@ 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,
|
||||
);
|
||||
|
||||
print(response.body);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
await reloadScreen(event, emit);
|
||||
} else {
|
||||
@@ -606,6 +671,49 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
return response;
|
||||
}
|
||||
|
||||
FutureOr<void> _removeImage(
|
||||
RemoveImageEvent event, Emitter<DiaryEditState> emit) async {
|
||||
if (state is DiaryEditLoadedState) {
|
||||
var currentState = state as DiaryEditLoadedState;
|
||||
|
||||
var response = await sendRemovePhoto(
|
||||
currentState.token,
|
||||
event.path,
|
||||
event.photoID,
|
||||
currentState.currentMeal?.id,
|
||||
currentState.diaryId,
|
||||
);
|
||||
print(response.statusCode);
|
||||
if (response.statusCode == 204) {
|
||||
await reloadScreen(event, emit);
|
||||
} else {
|
||||
print(
|
||||
'Failed to remove photo. Status Code: ${response.statusCode} ${response.body}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<http.Response> sendRemovePhoto(String? token, String? path,
|
||||
String? photoID, int? mealID, int diaryID) async {
|
||||
String url =
|
||||
'${dotenv.env['SERVER_ROOT']!}/diary/$diaryID/meal/$mealID/photo/delete';
|
||||
final Map<String, dynamic> credentials = {
|
||||
'id': photoID,
|
||||
'path': path,
|
||||
};
|
||||
var response = await http.delete(
|
||||
Uri.parse(url),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
body: json.encode(credentials),
|
||||
encoding: utf8,
|
||||
);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<void> _finishDay(FinishDay event, Emitter<DiaryEditState> emit) async {
|
||||
if (state is DiaryEditLoadedState) {
|
||||
var currentState = state as DiaryEditLoadedState;
|
||||
@@ -803,4 +911,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: "грамм"),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +98,14 @@ class UploadImages extends DiaryEditEvent {
|
||||
List<Object> get props => [image];
|
||||
}
|
||||
|
||||
class RemoveImageEvent extends DiaryEditEvent {
|
||||
RemoveImageEvent(this.photoID, this.path);
|
||||
final String photoID;
|
||||
final String path;
|
||||
@override
|
||||
List<Object> get props => [photoID, path];
|
||||
}
|
||||
|
||||
class ProductInput extends DiaryEditEvent {
|
||||
ProductInput(this.input);
|
||||
final String input;
|
||||
@@ -114,6 +122,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,
|
||||
@@ -38,6 +39,8 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
this.fatsController,
|
||||
this.proteinsController,
|
||||
this.carbsController,
|
||||
required this.recommendedChartValues,
|
||||
required this.consumedChartValues,
|
||||
required this.diaryId,
|
||||
required this.selectedSatiety,
|
||||
required this.moderationExpanded,
|
||||
@@ -52,7 +55,10 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
List<dynamic>? portions;
|
||||
List<dynamic>? photos;
|
||||
List<dynamic>? autocompleteList;
|
||||
List<int> recommendedChartValues;
|
||||
List<int> consumedChartValues;
|
||||
SelectionPopupModel? currentMeal;
|
||||
SelectionPopupModel? portionController;
|
||||
TimeOfDay? wakeupController;
|
||||
TimeOfDay? retireController;
|
||||
TimeOfDay? mealTimeController;
|
||||
@@ -77,6 +83,8 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
meals,
|
||||
portions,
|
||||
photos,
|
||||
recommendedChartValues,
|
||||
consumedChartValues,
|
||||
autocompleteList,
|
||||
wakeupController,
|
||||
retireController,
|
||||
@@ -84,6 +92,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
commentController,
|
||||
productNameController,
|
||||
productQuantityController,
|
||||
portionController,
|
||||
caloriesController,
|
||||
fatsController,
|
||||
proteinsController,
|
||||
@@ -99,8 +108,11 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
DiaryEditLoadedState copyWith({
|
||||
DiaryEditModel? diaryEditModelObj,
|
||||
SelectionPopupModel? currentMeal,
|
||||
SelectionPopupModel? portionController,
|
||||
String? diaryDate,
|
||||
String? token,
|
||||
List<int>? recommendedChartValues,
|
||||
List<int>? consumedChartValues,
|
||||
List<dynamic>? meals,
|
||||
List<dynamic>? portions,
|
||||
List<dynamic>? photos,
|
||||
@@ -129,10 +141,14 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
meals: meals ?? this.meals,
|
||||
autocompleteList: autocompleteList ?? this.autocompleteList,
|
||||
portions: portions ?? this.portions,
|
||||
recommendedChartValues:
|
||||
recommendedChartValues ?? this.recommendedChartValues,
|
||||
consumedChartValues: consumedChartValues ?? this.consumedChartValues,
|
||||
wakeupController: wakeupController ?? this.wakeupController,
|
||||
retireController: retireController ?? this.retireController,
|
||||
mealTimeController: mealTimeController ?? this.mealTimeController,
|
||||
commentController: commentController ?? this.commentController,
|
||||
portionController: portionController ?? this.portionController,
|
||||
productNameController:
|
||||
productNameController ?? this.productNameController,
|
||||
productQuantityController:
|
||||
|
||||
@@ -79,7 +79,7 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
SizedBox(height: 20.v),
|
||||
_buildMood(context, state),
|
||||
SizedBox(height: 30.v),
|
||||
_buildNutritionChart(context),
|
||||
_buildNutritionChart(context, state),
|
||||
SizedBox(height: 30.v),
|
||||
_buildComment(context, state),
|
||||
],
|
||||
@@ -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(),
|
||||
@@ -636,14 +653,36 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
_buildPhoto(BuildContext context, Map<String, dynamic> photo) {
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 10.h, vertical: 10.h),
|
||||
decoration: AppDecoration.fillGray.copyWith(
|
||||
borderRadius: BorderRadiusStyle.roundedBorder5,
|
||||
),
|
||||
child: Image.network(
|
||||
dotenv.env['STORAGE_URL']! + photo['path'],
|
||||
),
|
||||
return Stack(
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 10.h, vertical: 10.h),
|
||||
decoration: AppDecoration.fillGray.copyWith(
|
||||
borderRadius: BorderRadiusStyle.roundedBorder5,
|
||||
),
|
||||
child: Image.network(
|
||||
dotenv.env['STORAGE_URL']! + photo['path'],
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 5,
|
||||
right: 5,
|
||||
child: GestureDetector(
|
||||
onTap: removePhoto(context, photo),
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(5),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: Colors.transparent,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.close,
|
||||
color: appTheme.blueGray300,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -653,14 +692,18 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
};
|
||||
}
|
||||
|
||||
_buildNutritionChart(BuildContext context) {
|
||||
final List<double> recommendedValues = [
|
||||
2000,
|
||||
70,
|
||||
50,
|
||||
300
|
||||
]; // Рекомендуемые значения: калории, жиры, белки, углеводы
|
||||
final List<double> consumedValues = [1800, 60, 40, 250]; //
|
||||
removePhoto(BuildContext context, Map<String, dynamic> photo) {
|
||||
return () {
|
||||
context
|
||||
.read<DiaryEditBloc>()
|
||||
.add(RemoveImageEvent(photo['id'].toString(), photo['path']));
|
||||
};
|
||||
}
|
||||
|
||||
_buildNutritionChart(BuildContext context, DiaryEditLoadedState state) {
|
||||
final List<int> recommendedValues = state
|
||||
.recommendedChartValues; // Рекомендуемые значения: калории, жиры, белки, углеводы
|
||||
final List<int> consumedValues = state.consumedChartValues; //
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 16.h),
|
||||
padding: EdgeInsets.symmetric(
|
||||
@@ -1163,7 +1206,7 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
bool checkConsumedValues(
|
||||
List<double> recommendedValues, List<double> consumedValues) {
|
||||
List<int> recommendedValues, List<int> consumedValues) {
|
||||
for (int i = 0; i < recommendedValues.length; i++) {
|
||||
if (consumedValues[i] > recommendedValues[i]) {
|
||||
// Если хотя бы одно потребленное значение превышает рекомендованное
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import '/core/app_export.dart';
|
||||
import 'package:eatvio_app/presentation/profile/my_profile_screen/models/my_profile_model.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
import 'package:hive/hive.dart';
|
||||
//import 'package:hive/hive.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
|
||||
part 'my_profile_event.dart';
|
||||
@@ -21,8 +21,10 @@ class MyProfileBloc extends Bloc<MyProfileEvent, MyProfileState> {
|
||||
Emitter<MyProfileState> emit,
|
||||
) async {
|
||||
try {
|
||||
final box = await Hive.openBox('token');
|
||||
final token = box.get('token');
|
||||
/*final box = await Hive.openBox('token');
|
||||
final token = box.get('token');*/
|
||||
final token =
|
||||
"9|laravel_sanctum_KFXbccDcWEvTPfJmV99EQv1neAggmpR2TidVGDPN34fa201a";
|
||||
final response = await http.get(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/profile/index'),
|
||||
headers: {
|
||||
|
||||
@@ -44,7 +44,7 @@ class MySettingsScreen extends StatelessWidget {
|
||||
_buildSetingsScreen(BuildContext context, MyProfileLoadedState state) {
|
||||
mediaQueryData = MediaQuery.of(context);
|
||||
|
||||
SafeArea(
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
appBar: _buildAppBar(context, "my_settings".tr),
|
||||
body: Padding(
|
||||
|
||||
@@ -27,6 +27,8 @@ void main() {
|
||||
portions: [],
|
||||
wakeupExpanded: false,
|
||||
moderationExpanded: false,
|
||||
recommendedChartValues: [10, 10, 10, 10],
|
||||
consumedChartValues: [1, 2, 3, 4],
|
||||
moodExpanded: false);
|
||||
|
||||
await tester.pumpWidget(
|
||||
|
||||
Reference in New Issue
Block a user