merge fromdiary to main

This commit is contained in:
Anatoliy Poloz
2024-06-19 12:12:00 +03:00
90 changed files with 4667 additions and 4314 deletions

View File

@@ -1,5 +1,6 @@
// ignore_for_file: unused_local_variable
import 'bloc/diary_edit_bloc.dart';
import 'models/diary_edit_model.dart';
import 'package:flutter/material.dart';
@@ -13,22 +14,15 @@ 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';
import 'package:carousel_slider/carousel_slider.dart';
// ignore: must_be_immutable
class DiaryEditScreen extends StatelessWidget {
final void Function() onInitialize;
DiaryEditScreen({Key? key, required this.onInitialize}) : super(key: key);
DiaryEditScreen({Key? key}) : super(key: key);
static Widget builder(BuildContext context) {
return BlocProvider<DiaryEditBloc>(
create: (context) =>
DiaryEditBloc(DiaryEditState(diaryEditModelObj: DiaryEditModel()))
..add(DiaryEditInitialEvent()),
child: DiaryEditScreen(
onInitialize: () {},
));
create: (context) => DiaryEditBloc(DiaryEditState(diaryEditModelObj: DiaryEditModel()))..add(DiaryEditInitialEvent()), child: DiaryEditScreen());
}
Widget build(BuildContext context) {
@@ -53,56 +47,52 @@ class DiaryEditScreen extends StatelessWidget {
);
}
Widget _buildDiaryEditScreen(
BuildContext context, DiaryEditLoadedState state) {
mediaQueryData = MediaQuery.of(context);
Widget _buildDiaryEditScreen(BuildContext context, DiaryEditLoadedState state) {
return RefreshIndicator(
onRefresh: refreshPage(context),
child: Stack(
alignment: Alignment.bottomCenter,
children: [
FormBuilder(
child: Scaffold(
backgroundColor: Color.fromARGB(255, 240, 242, 245),
resizeToAvoidBottomInset: true,
body: SafeArea(
child: SizedBox(
width: double.maxFinite,
child: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(bottom: 5.v),
child: Column(
children: [
_buildHeaderRow(context, state),
SizedBox(height: 30.v),
_buildWakupRetire(context, state),
SizedBox(height: 30.v),
_buildMeal(context, state),
SizedBox(height: 20.v),
_buildMood(context, state),
SizedBox(height: 30.v),
_buildNutritionChart(context, state),
SizedBox(height: 30.v),
_buildComment(context, state),
],
),
appBar: AppBar(
toolbarHeight: 0,
automaticallyImplyLeading: false,
),
backgroundColor: Color.fromARGB(255, 240, 242, 245),
resizeToAvoidBottomInset: true,
body: SizedBox(
width: double.maxFinite,
child: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.only(bottom: 5.v),
child: Column(
children: [
_buildHeaderRow(context, state),
SizedBox(height: 30.v),
_buildWakupRetire(context, state),
SizedBox(height: 30.v),
_buildMeal(context, state),
SizedBox(height: 20.v),
_buildMood(context, state),
SizedBox(height: 30.v),
_buildNutritionChart(context, state),
SizedBox(height: 30.v),
_buildComment(context, state),
],
),
),
),
],
),
),
],
),
),
bottomNavigationBar: _buildBottomBar(context) ),
),
Positioned(
left: 16.h,
right: 16.h,
bottom: 50.v, // Adjusted position to lift the button higher
child: _buildEndDay(context),
),
_buildEndDay(context),
],
),
);
@@ -114,7 +104,7 @@ class DiaryEditScreen extends StatelessWidget {
margin: EdgeInsets.only(
left: 16.h,
right: 16.h,
bottom: 41.v,
bottom: 16.v,
),
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
decoration: BoxDecoration(
@@ -153,10 +143,8 @@ class DiaryEditScreen extends StatelessWidget {
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisAlignment: MainAxisAlignment.center,
children: [
CustomImageView(
imagePath: ImageConstant.imgArrowLeft, onTap: onTapBack()),
Padding(
padding: EdgeInsets.only(top: 1.v),
child: Column(
@@ -181,16 +169,6 @@ class DiaryEditScreen extends StatelessWidget {
);
}
onTapBack() {
return () {
NavigatorService.goBack();
};
}
_buildBottomBar(BuildContext context) {
return CustomBottomBar(onChanged: (BottomBarEnum type) {});
}
/// Section Widget
_buildAddProduct(BuildContext context, DiaryEditLoadedState state) {
return CustomOutlinedButton(
@@ -259,9 +237,7 @@ class DiaryEditScreen extends StatelessWidget {
borderRadius: BorderRadiusStyle.roundedBorder5,
),
child: Center(
child: CircularProgressIndicator(
color: appTheme
.blueGray300), // Замените на свой прелоадер при необходимости
child: CircularProgressIndicator(color: appTheme.blueGray300), // Замените на свой прелоадер при необходимости
),
),
],
@@ -285,8 +261,7 @@ class DiaryEditScreen extends StatelessWidget {
_buildMeal(BuildContext context, DiaryEditLoadedState state) {
final digitsOnly = FilteringTextInputFormatter.digitsOnly;
List<String> _options =
state.autocompleteList!.map((dynamic item) => item as String).toList();
List<String> _options = state.autocompleteList!.map((dynamic item) => item as String).toList();
//print(_options);
FocusNode focusNodeName = FocusNode();
return Container(
@@ -331,9 +306,7 @@ class DiaryEditScreen extends StatelessWidget {
onTap: () => _selectMealTime(context, state),
child: AbsorbPointer(
child: CustomTextFormField(
hintText: state.mealTimeController
?.format(context)
.toString(),
hintText: state.mealTimeController?.format(context).toString(),
autofocus: false,
),
),
@@ -347,8 +320,7 @@ class DiaryEditScreen extends StatelessWidget {
SizedBox(height: 20.v),
Padding(
padding: EdgeInsets.symmetric(horizontal: 10.h),
child: BlocSelector<DiaryEditBloc, DiaryEditState,
DiaryEditModel?>(
child: BlocSelector<DiaryEditBloc, DiaryEditState, DiaryEditModel?>(
selector: (state) => state.diaryEditModelObj,
builder: (context, diaryEditModelObj) {
return CustomDropDown(
@@ -440,8 +412,7 @@ class DiaryEditScreen extends StatelessWidget {
),
Padding(
padding: EdgeInsets.only(left: 30.h),
child: BlocSelector<DiaryEditBloc, DiaryEditState,
DiaryEditModel?>(
child: BlocSelector<DiaryEditBloc, DiaryEditState, DiaryEditModel?>(
selector: (state) => state.diaryEditModelObj,
builder: (context, diaryEditModelObj) {
return CustomDropDown(
@@ -459,9 +430,7 @@ class DiaryEditScreen extends StatelessWidget {
SizedBox(height: 30.v),
_buildAddProduct(context, state),
SizedBox(height: 30.v),
...state.portions!
.map((portion) => _buildProduct(context, portion))
.toList(),
...state.portions!.map((portion) => _buildProduct(context, portion)).toList(),
SizedBox(height: 30.v),
/*...state.photos != null
? state.photos!.isEmpty
@@ -574,14 +543,8 @@ class DiaryEditScreen extends StatelessWidget {
child: Text('Отмена'),
),
TextButton(
onPressed: triggerModeration(
context,
state.productNameController!.text,
state.caloriesController!.text,
state.proteinsController!.text,
state.fatsController!.text,
state.carbsController!.text,
dialogContext),
onPressed: triggerModeration(context, state.productNameController!.text, state.caloriesController!.text, state.proteinsController!.text,
state.fatsController!.text, state.carbsController!.text, dialogContext),
child: Text('Отправить'),
),
],
@@ -590,30 +553,19 @@ class DiaryEditScreen extends StatelessWidget {
);
}
triggerModeration(
BuildContext context,
String name,
String energyOn100gr,
String proteinsOn100gr,
String fatsOn100gr,
String carbohydratesOn100gr,
triggerModeration(BuildContext context, String name, String energyOn100gr, String proteinsOn100gr, String fatsOn100gr, String carbohydratesOn100gr,
BuildContext dialogContext) {
return () {
// Call function to send moderation with the entered values
context.read<DiaryEditBloc>().add(SendModeration(
name: name,
energyOn100gr: energyOn100gr,
proteinsOn100gr: proteinsOn100gr,
fatsOn100gr: fatsOn100gr,
carbohydratesOn100gr: carbohydratesOn100gr));
name: name, energyOn100gr: energyOn100gr, proteinsOn100gr: proteinsOn100gr, fatsOn100gr: fatsOn100gr, carbohydratesOn100gr: carbohydratesOn100gr));
Navigator.of(dialogContext).pop(); // Dismiss the dialog
};
}
popDialog(BuildContext dialogContext) {
return () {
Navigator.of(dialogContext)
.pop(); // Dismiss the dialog on Cancel button press
Navigator.of(dialogContext).pop(); // Dismiss the dialog on Cancel button press
};
}
@@ -623,8 +575,7 @@ class DiaryEditScreen extends StatelessWidget {
};
}
selectProduct(AutocompleteOnSelected<String> onSelected, String option,
DiaryEditLoadedState state) {
selectProduct(AutocompleteOnSelected<String> onSelected, String option, DiaryEditLoadedState state) {
state.productNameController?.text = option;
return () {
onSelected(option);
@@ -652,9 +603,7 @@ class DiaryEditScreen extends StatelessWidget {
changeMeal(BuildContext context, DiaryEditLoadedState state) {
return (value) {
context
.read<DiaryEditBloc>()
.add(ChangeMeal(meals: state.meals, value: value));
context.read<DiaryEditBloc>().add(ChangeMeal(meals: state.meals, value: value));
};
}
@@ -671,8 +620,7 @@ class DiaryEditScreen extends StatelessWidget {
return CarouselSlider(
options: CarouselOptions(height: 340.0),
items: state.photos!.map<Widget>((photo) {
return _buildPhoto(
context, photo); // Assuming photos are stored as strings
return _buildPhoto(context, photo); // Assuming photos are stored as strings
}).toList(),
);
}
@@ -698,9 +646,7 @@ class DiaryEditScreen extends StatelessWidget {
top: 5.v,
),
child: Text(
portion['product_name'].length > 8
? portion['product_name'].substring(0, 8)
: portion['product_name'],
portion['product_name'].length > 8 ? portion['product_name'].substring(0, 8) : portion['product_name'],
style: CustomTextStyles.titleMedium16,
)),
Padding(
@@ -710,9 +656,7 @@ class DiaryEditScreen extends StatelessWidget {
bottom: 3.v,
),
child: Text(
portion['quantity'].toString() +
' ' +
portion['portion'].toString().tr,
portion['quantity'].toString() + ' ' + portion['portion'].toString().tr,
),
),
Spacer(),
@@ -772,15 +716,12 @@ class DiaryEditScreen extends StatelessWidget {
removePhoto(BuildContext context, Map<String, dynamic> photo) {
return () {
context
.read<DiaryEditBloc>()
.add(RemoveImageEvent(photo['id'].toString(), photo['path']));
context.read<DiaryEditBloc>().add(RemoveImageEvent(photo['id'].toString(), photo['path']));
};
}
_buildNutritionChart(BuildContext context, DiaryEditLoadedState state) {
final List<int> recommendedValues = state
.recommendedChartValues; // Рекомендуемые значения: калории, жиры, белки, углеводы
final List<int> recommendedValues = state.recommendedChartValues; // Рекомендуемые значения: калории, жиры, белки, углеводы
final List<int> consumedValues = state.consumedChartValues; //
return Container(
margin: EdgeInsets.symmetric(horizontal: 16.h),
@@ -842,37 +783,25 @@ class DiaryEditScreen extends StatelessWidget {
BarChartGroupData(x: 0, barRods: [
BarChartRodData(
toY: consumedValues[0] / recommendedValues[0] * 100,
color: checkConsumedValues(
[recommendedValues[0]], [consumedValues[1]])
? Colors.red
: Colors.blue,
color: checkConsumedValues([recommendedValues[0]], [consumedValues[1]]) ? Colors.red : Colors.blue,
)
]),
BarChartGroupData(x: 1, barRods: [
BarChartRodData(
toY: consumedValues[1] / recommendedValues[1] * 100,
color: checkConsumedValues(
[recommendedValues[1]], [consumedValues[1]])
? Colors.red
: Colors.blue,
color: checkConsumedValues([recommendedValues[1]], [consumedValues[1]]) ? Colors.red : Colors.blue,
)
]),
BarChartGroupData(x: 2, barRods: [
BarChartRodData(
toY: consumedValues[2] / recommendedValues[2] * 100,
color: checkConsumedValues(
[recommendedValues[2]], [consumedValues[2]])
? Colors.red
: Colors.blue,
color: checkConsumedValues([recommendedValues[2]], [consumedValues[2]]) ? Colors.red : Colors.blue,
)
]),
BarChartGroupData(x: 3, barRods: [
BarChartRodData(
toY: consumedValues[3] / recommendedValues[3] * 100,
color: checkConsumedValues(
[recommendedValues[3]], [consumedValues[3]])
? Colors.red
: Colors.blue,
color: checkConsumedValues([recommendedValues[3]], [consumedValues[3]]) ? Colors.red : Colors.blue,
)
]),
],
@@ -1062,9 +991,7 @@ class DiaryEditScreen extends StatelessWidget {
r"Подъем \ отход ко сну",
style: CustomTextStyles.bodyMediumBlack900,
),
Icon(state.wakeupExpanded
? Icons.arrow_drop_up
: Icons.arrow_drop_down),
Icon(state.wakeupExpanded ? Icons.arrow_drop_up : Icons.arrow_drop_down),
],
),
),
@@ -1078,8 +1005,7 @@ class DiaryEditScreen extends StatelessWidget {
onTap: () => _selectWakeupTime(context, state),
child: AbsorbPointer(
child: CustomTextFormField(
hintText:
state.wakeupController?.format(context).toString(),
hintText: state.wakeupController?.format(context).toString(),
prefix: Icon(Icons.sunny),
autofocus: false,
),
@@ -1090,8 +1016,7 @@ class DiaryEditScreen extends StatelessWidget {
onTap: () => _selectRetireTime(context, state),
child: AbsorbPointer(
child: CustomTextFormField(
hintText:
state.retireController?.format(context).toString(),
hintText: state.retireController?.format(context).toString(),
prefix: Icon(Icons.bed),
autofocus: false,
),
@@ -1138,8 +1063,7 @@ class DiaryEditScreen extends StatelessWidget {
};
}
Function() sendFinishDayData(
BuildContext dialogContext, BuildContext context) {
Function() sendFinishDayData(BuildContext dialogContext, BuildContext context) {
return () {
closeDialog(dialogContext);
context.read<DiaryEditBloc>().add(FinishDay());
@@ -1181,9 +1105,7 @@ class DiaryEditScreen extends StatelessWidget {
"Ваше настроение после приема пищи",
style: CustomTextStyles.bodyMediumBlack900,
),
Icon(state.moodExpanded
? Icons.arrow_drop_up
: Icons.arrow_drop_down),
Icon(state.moodExpanded ? Icons.arrow_drop_up : Icons.arrow_drop_down),
],
),
),
@@ -1241,8 +1163,7 @@ class DiaryEditScreen extends StatelessWidget {
};
}
Future<void> _selectWakeupTime(
BuildContext context, DiaryEditLoadedState state) async {
Future<void> _selectWakeupTime(BuildContext context, DiaryEditLoadedState state) async {
final TimeOfDay? pickedTime = await showTimePicker(
context: context,
initialTime: state.wakeupController ?? TimeOfDay.now(),
@@ -1253,8 +1174,7 @@ class DiaryEditScreen extends StatelessWidget {
}
}
Future<void> _selectRetireTime(
BuildContext context, DiaryEditLoadedState state) async {
Future<void> _selectRetireTime(BuildContext context, DiaryEditLoadedState state) async {
final TimeOfDay? pickedTime = await showTimePicker(
context: context,
initialTime: state.retireController ?? TimeOfDay.now(),
@@ -1265,8 +1185,7 @@ class DiaryEditScreen extends StatelessWidget {
}
}
Future<void> _selectMealTime(
BuildContext context, DiaryEditLoadedState state) async {
Future<void> _selectMealTime(BuildContext context, DiaryEditLoadedState state) async {
final TimeOfDay? pickedTime = await showTimePicker(
context: context,
initialTime: state.mealTimeController ?? TimeOfDay.now(),
@@ -1278,8 +1197,7 @@ class DiaryEditScreen extends StatelessWidget {
}
}
bool checkConsumedValues(
List<int> recommendedValues, List<int> consumedValues) {
bool checkConsumedValues(List<int> recommendedValues, List<int> consumedValues) {
for (int i = 0; i < recommendedValues.length; i++) {
if (consumedValues[i] > recommendedValues[i]) {
// Если хотя бы одно потребленное значение превышает рекомендованное