feat(diary): Remove photo is now an icon over the picture

This commit is contained in:
2024-08-08 17:12:44 +03:00
parent c5c6ec0e98
commit 16d0863958

View File

@@ -284,61 +284,62 @@ class DiaryScreen extends StatelessWidget {
/// Section Widget
_buildAddPhoto(BuildContext context, DiaryStateLoaded state) {
bool isLoading = state.isLoading;
return GestureDetector(
onTap: addImage(context, isLoading),
child: Stack(
children: [
if (!isLoading)
Container(
margin: EdgeInsets.symmetric(horizontal: 10.h),
padding: EdgeInsets.symmetric(
horizontal: 40.h,
vertical: 80.v,
),
decoration: AppDecoration.fillGray.copyWith(
borderRadius: BorderRadiusStyle.roundedBorder5,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: EdgeInsets.only(
left: 7.h,
top: 5.v,
if (state.currentMeal.photos.isEmpty)
return GestureDetector(
onTap: addImage(context, isLoading),
child: Stack(
children: [
if (!isLoading)
Container(
margin: EdgeInsets.symmetric(horizontal: 10.h),
padding: EdgeInsets.symmetric(
horizontal: 40.h,
vertical: 80.v,
),
decoration: AppDecoration.fillGray.copyWith(
borderRadius: BorderRadiusStyle.roundedBorder5,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: EdgeInsets.only(
left: 7.h,
top: 5.v,
),
child: Text(
"Добавить фото",
selectionColor: appTheme.blueA400,
),
),
child: Text(
"Добавить фото",
selectionColor: appTheme.blueA400,
Spacer(),
Icon(
Icons.photo_library,
color: appTheme.blueGray300,
),
),
Spacer(),
Icon(
Icons.photo_library,
color: appTheme.blueGray300,
),
],
],
),
),
),
if (isLoading)
Container(
margin: EdgeInsets.symmetric(horizontal: 10.h),
padding: EdgeInsets.symmetric(
horizontal: 40.h,
vertical: 80.v,
if (isLoading)
Container(
margin: EdgeInsets.symmetric(horizontal: 10.h),
padding: EdgeInsets.symmetric(
horizontal: 40.h,
vertical: 80.v,
),
decoration: AppDecoration.fillGray.copyWith(
borderRadius: BorderRadiusStyle.roundedBorder5,
),
child: Center(
child: CircularProgressIndicator(color: appTheme.blueGray300), // Замените на свой прелоадер при необходимости
),
),
decoration: AppDecoration.fillGray.copyWith(
borderRadius: BorderRadiusStyle.roundedBorder5,
),
child: Center(
child: CircularProgressIndicator(
color: appTheme
.blueGray300), // Замените на свой прелоадер при необходимости
),
),
],
),
);
],
),
);
else
return Container();
}
addImage(BuildContext context, bool isLoading) {
@@ -357,8 +358,7 @@ class DiaryScreen extends StatelessWidget {
_buildMeal(BuildContext context, DiaryStateLoaded state) {
final digitsOnly = FilteringTextInputFormatter.digitsOnly;
List<String> _options =
state.autocompleteList.map((Product item) => item.name).toList();
List<String> _options = state.autocompleteList.map((Product item) => item.name).toList();
FocusNode focusNodeName = FocusNode();
return Container(
padding: EdgeInsets.symmetric(
@@ -393,9 +393,7 @@ class DiaryScreen extends StatelessWidget {
onTap: () => _selectMealTime(context, state),
child: AbsorbPointer(
child: CustomTextFormField(
hintText: state.mealTimeController
?.format(context)
.toString(),
hintText: state.mealTimeController?.format(context).toString(),
autofocus: false,
),
),
@@ -531,9 +529,7 @@ class DiaryScreen extends StatelessWidget {
SizedBox(height: 24.v),
_buildAddProduct(context, state),
SizedBox(height: 24.v),
...state.portions
.map((portion) => _buildProduct(context, portion))
.toList(),
...state.portions.map((portion) => _buildProduct(context, portion)).toList(),
SizedBox(height: 24.v),
_buildCarousel(context, state),
SizedBox(height: 24.v),
@@ -682,8 +678,7 @@ class DiaryScreen extends StatelessWidget {
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
};
}
@@ -693,8 +688,7 @@ class DiaryScreen extends StatelessWidget {
};
}
selectProduct(AutocompleteOnSelected<String> onSelected, String option,
DiaryStateLoaded state) {
selectProduct(AutocompleteOnSelected<String> onSelected, String option, DiaryStateLoaded state) {
state.product_nameController.text = option;
return () {
onSelected(option);
@@ -762,9 +756,7 @@ class DiaryScreen 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,
),
),
@@ -804,24 +796,42 @@ class DiaryScreen extends StatelessWidget {
),
child: Image.network(
baseUrl + '/storage/' + photo.path,
fit: BoxFit.cover, // Чтобы изображение занимало весь контейнер
),
),
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,
bottom: 0,
left: 0,
right: 0,
child: Container(
height: 50.h, // Высота затемненной области
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.black.withOpacity(0.7), // Цвет затемнения
Colors.transparent,
],
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
icon: Icon(Icons.photo_outlined),
color: Colors.white,
onPressed: () {
// Ваш код для кнопки фотографии
},
),
IconButton(
icon: Icon(Icons.delete_outlined),
color: Colors.white,
onPressed: () => removePhoto(context, photo),
),
],
),
),
),
],
@@ -836,9 +846,7 @@ class DiaryScreen extends StatelessWidget {
removePhoto(BuildContext context, Photo photo) {
return () {
context
.read<DiaryBloc>()
.add(RemoveImageEvent(photo.id.toString(), photo.path));
context.read<DiaryBloc>().add(RemoveImageEvent(photo.id.toString(), photo.path));
};
}
@@ -898,9 +906,7 @@ class DiaryScreen 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),
],
),
),
@@ -914,8 +920,7 @@ class DiaryScreen 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,
),
@@ -926,8 +931,7 @@ class DiaryScreen 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,
),
@@ -974,8 +978,7 @@ class DiaryScreen extends StatelessWidget {
};
}
Function() sendFinishDayData(
BuildContext dialogContext, BuildContext context) {
Function() sendFinishDayData(BuildContext dialogContext, BuildContext context) {
return () {
closeDialog(dialogContext);
context.read<DiaryBloc>().add(FinishDay());
@@ -1009,9 +1012,7 @@ class DiaryScreen 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),
],
),
),
@@ -1071,8 +1072,7 @@ class DiaryScreen extends StatelessWidget {
};
}
Future<void> _selectWakeupTime(
BuildContext context, DiaryStateLoaded state) async {
Future<void> _selectWakeupTime(BuildContext context, DiaryStateLoaded state) async {
final TimeOfDay? pickedTime = await showTimePicker(
context: context,
initialTime: state.wakeupController,
@@ -1082,8 +1082,7 @@ class DiaryScreen extends StatelessWidget {
}
}
Future<void> _selectRetireTime(
BuildContext context, DiaryStateLoaded state) async {
Future<void> _selectRetireTime(BuildContext context, DiaryStateLoaded state) async {
final TimeOfDay? pickedTime = await showTimePicker(
context: context,
initialTime: state.retireController,
@@ -1093,8 +1092,7 @@ class DiaryScreen extends StatelessWidget {
}
}
Future<void> _selectMealTime(
BuildContext context, DiaryStateLoaded state) async {
Future<void> _selectMealTime(BuildContext context, DiaryStateLoaded state) async {
final TimeOfDay? pickedTime = await showTimePicker(
context: context,
initialTime: state.mealTimeController ?? TimeOfDay.now(),
@@ -1105,8 +1103,7 @@ class DiaryScreen 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]) {
// Если хотя бы одно потребленное значение превышает рекомендованное