forked from eatvio/eatvio_app
refactor(diary): Compiled version apk: profile, settings, diarym registration, auth, navigation bar
This commit is contained in:
@@ -89,9 +89,10 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
diaryEditModelObj: currentState.diaryEditModelObj));
|
||||
} else {
|
||||
// Если текущее состояние - начальное, создаем новое загруженное состояние
|
||||
final List<SelectionPopupModel> meals =
|
||||
fillMealList(diary['meals']);
|
||||
emit(DiaryEditLoadedState(
|
||||
currentMeal: SelectionPopupModel(
|
||||
id: 1, title: "Прием пищи 1", isSelected: true),
|
||||
currentMeal: meals[0],
|
||||
portionController: SelectionPopupModel(
|
||||
id: 0, title: "порций", isSelected: true),
|
||||
wakeupExpanded: true,
|
||||
@@ -120,8 +121,8 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
diaryId: diaryId,
|
||||
diaryDate: diaryDate,
|
||||
autocompleteList: [],
|
||||
diaryEditModelObj: state.diaryEditModelObj?.copyWith(
|
||||
mealList: fillMealList(), portionList: fillPortions())));
|
||||
diaryEditModelObj: state.diaryEditModelObj
|
||||
?.copyWith(mealList: meals, portionList: fillPortions())));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
@@ -200,7 +201,18 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
}
|
||||
}
|
||||
|
||||
reloadScreen(DiaryEditEvent event, Emitter<DiaryEditState> emit) async {
|
||||
refreshScreen(
|
||||
int mealID,
|
||||
DiaryEditEvent event,
|
||||
Emitter<DiaryEditState> emit,
|
||||
) async {
|
||||
await reloadScreen(event, emit);
|
||||
}
|
||||
|
||||
reloadScreen(
|
||||
DiaryEditEvent event,
|
||||
Emitter<DiaryEditState> emit,
|
||||
) async {
|
||||
print("Reloading...");
|
||||
try {
|
||||
final token =
|
||||
@@ -244,45 +256,46 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
responseChart.body)['dailyNutritionRecommendation'];
|
||||
final consumedChartValues =
|
||||
jsonDecode(responseChart.body)['dailyNutritionIntake'];
|
||||
final List<SelectionPopupModel> meals =
|
||||
fillMealList(diary['meals']);
|
||||
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()))));
|
||||
diaryEditModelObj: state.diaryEditModelObj?.copyWith(
|
||||
mealList: meals, portionList: fillPortions()),
|
||||
currentMeal: meals[0],
|
||||
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: [],
|
||||
)));
|
||||
|
||||
print("Updated");
|
||||
} catch (e) {
|
||||
@@ -364,6 +377,8 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
currentState.diaryId);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
print(
|
||||
'Mood change success! meal_id: ${currentState.currentMeal?.id}, mood: ${event.selectedElement}');
|
||||
updatedState.selectedMood = event.selectedElement;
|
||||
emit(updatedState); // Передаем обновленное состояние в emit
|
||||
}
|
||||
@@ -511,11 +526,10 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
if (state is DiaryEditLoadedState) {
|
||||
var currentState = state as DiaryEditLoadedState;
|
||||
final meal = currentState.meals?.firstWhere(
|
||||
(meal) => meal['type'] == event.value.id,
|
||||
(meal) => meal['id'] == event.value.id,
|
||||
orElse: () => null);
|
||||
|
||||
print(meal);
|
||||
int? id = event.value.id;
|
||||
print(meal['photos']);
|
||||
DiaryEditLoadedState updatedState = currentState.copyWith(
|
||||
currentMeal: event.value,
|
||||
portions: meal['portions'],
|
||||
@@ -523,6 +537,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
mealTimeController: toTime(meal['time'] ?? "1$id:00"),
|
||||
selectedMood: meal['mood'],
|
||||
selectedSatiety: meal['satiety']);
|
||||
print(updatedState.photos);
|
||||
emit(updatedState);
|
||||
}
|
||||
}
|
||||
@@ -916,15 +931,16 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
return timeOfDay;
|
||||
}
|
||||
|
||||
List<SelectionPopupModel> fillMealList() {
|
||||
return [
|
||||
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"),
|
||||
];
|
||||
List<SelectionPopupModel> fillMealList(List<dynamic> meals) {
|
||||
meals.sort(compareTypes);
|
||||
return meals.map((meal) {
|
||||
String title = "Прием пищи ${meal['type']}";
|
||||
return SelectionPopupModel(id: meal['id'], title: title);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
int compareTypes(a, b) {
|
||||
return a['type'].compareTo(b['type']);
|
||||
}
|
||||
|
||||
List<SelectionPopupModel> fillPortions() {
|
||||
|
||||
@@ -139,6 +139,7 @@ class DiaryEditLoadedState extends DiaryEditState {
|
||||
diaryDate: diaryDate ?? this.diaryDate,
|
||||
token: token ?? this.token,
|
||||
meals: meals ?? this.meals,
|
||||
photos: photos ?? this.photos,
|
||||
autocompleteList: autocompleteList ?? this.autocompleteList,
|
||||
portions: portions ?? this.portions,
|
||||
recommendedChartValues:
|
||||
|
||||
@@ -13,6 +13,7 @@ import 'package:eatvio_app/widgets/custom_edit_text_form_field.dart';
|
||||
import 'package:eatvio_app/widgets/custom_edit_drop_down.dart';
|
||||
import 'package:eatvio_app/widgets/custom_outlined_button.dart';
|
||||
import 'package:eatvio_app/widgets/custom_scale_element.dart';
|
||||
import 'package:eatvio_app/widgets/custom_bottom_bar.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class DiaryEditScreen extends StatelessWidget {
|
||||
@@ -229,7 +230,6 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
state.autocompleteList!.map((dynamic item) => item as String).toList();
|
||||
//print(_options);
|
||||
FocusNode focusNodeName = FocusNode();
|
||||
FocusNode focusNodeQuantity = FocusNode();
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 16.h),
|
||||
padding: EdgeInsets.symmetric(
|
||||
@@ -318,10 +318,7 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
hintText: "Введите название продукта",
|
||||
controller: productEditingController,
|
||||
focusNode: focusNodeName,
|
||||
onChanged: getAutocomplete(context, focusNodeQuantity),
|
||||
/*onFieldSubmitted: (String value) {
|
||||
onFieldSubmitted();
|
||||
},*/
|
||||
onChanged: getAutocomplete(context, focusNodeName),
|
||||
);
|
||||
},
|
||||
optionsViewBuilder: (
|
||||
@@ -341,7 +338,7 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final String option = options.elementAt(index);
|
||||
return GestureDetector(
|
||||
onTap: selectProduct(onSelected, option),
|
||||
onTap: selectProduct(onSelected, option, state),
|
||||
child: ListTile(
|
||||
title: Text(option),
|
||||
),
|
||||
@@ -374,7 +371,7 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
width: 150.h,
|
||||
hintText: "Кол-во",
|
||||
textInputAction: TextInputAction.done,
|
||||
focusNode: focusNodeQuantity,
|
||||
// focusNode: focusNodeQuantity,
|
||||
controller: state.productQuantityController,
|
||||
keyboardType: TextInputType.number,
|
||||
inputFormatters: <TextInputFormatter>[digitsOnly],
|
||||
@@ -405,10 +402,12 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
.toList(),
|
||||
SizedBox(height: 30.v),
|
||||
...state.photos != null
|
||||
? state.photos!
|
||||
.map((photo) => _buildPhoto(context, photo))
|
||||
.toList()
|
||||
: [],
|
||||
? state.photos!.isEmpty
|
||||
? [Text('Фото пока нет')]
|
||||
: state.photos!
|
||||
.map((photo) => _buildPhoto(context, photo))
|
||||
.toList()
|
||||
: [Text('Фото нет')],
|
||||
SizedBox(height: 20.v),
|
||||
_buildAddPhoto(context),
|
||||
SizedBox(height: 30.v),
|
||||
@@ -561,7 +560,9 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
};
|
||||
}
|
||||
|
||||
selectProduct(AutocompleteOnSelected<String> onSelected, String option) {
|
||||
selectProduct(AutocompleteOnSelected<String> onSelected, String option,
|
||||
DiaryEditLoadedState state) {
|
||||
state.productNameController?.text = option;
|
||||
return () {
|
||||
onSelected(option);
|
||||
};
|
||||
@@ -764,25 +765,37 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
BarChartGroupData(x: 0, barRods: [
|
||||
BarChartRodData(
|
||||
toY: consumedValues[0] / recommendedValues[0] * 100,
|
||||
color: Colors.blue,
|
||||
color: checkConsumedValues(
|
||||
[recommendedValues[0]], [consumedValues[1]])
|
||||
? Colors.red
|
||||
: Colors.blue,
|
||||
)
|
||||
]),
|
||||
BarChartGroupData(x: 1, barRods: [
|
||||
BarChartRodData(
|
||||
toY: consumedValues[1] / recommendedValues[1] * 100,
|
||||
color: Colors.red,
|
||||
color: checkConsumedValues(
|
||||
[recommendedValues[1]], [consumedValues[1]])
|
||||
? Colors.red
|
||||
: Colors.blue,
|
||||
)
|
||||
]),
|
||||
BarChartGroupData(x: 2, barRods: [
|
||||
BarChartRodData(
|
||||
toY: consumedValues[2] / recommendedValues[2] * 100,
|
||||
color: Colors.green,
|
||||
color: checkConsumedValues(
|
||||
[recommendedValues[2]], [consumedValues[2]])
|
||||
? Colors.red
|
||||
: Colors.blue,
|
||||
)
|
||||
]),
|
||||
BarChartGroupData(x: 3, barRods: [
|
||||
BarChartRodData(
|
||||
toY: consumedValues[3] / recommendedValues[3] * 100,
|
||||
color: Colors.orange,
|
||||
color: checkConsumedValues(
|
||||
[recommendedValues[3]], [consumedValues[3]])
|
||||
? Colors.red
|
||||
: Colors.blue,
|
||||
)
|
||||
]),
|
||||
],
|
||||
@@ -889,7 +902,7 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
SizedBox(height: 19.v),
|
||||
if (checkConsumedValues(recommendedValues, consumedValues))
|
||||
Text(
|
||||
"*Превышенная суточная норма углеводов",
|
||||
"*Превышенная суточная норма",
|
||||
style: theme.textTheme.labelLarge,
|
||||
)
|
||||
],
|
||||
@@ -1042,7 +1055,6 @@ class DiaryEditScreen extends StatelessWidget {
|
||||
|
||||
Function() onFinishDayPressed(BuildContext context) {
|
||||
return () {
|
||||
print("sad");
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext dialogContext) {
|
||||
|
||||
Reference in New Issue
Block a user