forked from eatvio/eatvio_app
feat: diary
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_cubit.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/widgets/add_product_modal.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class AddProductButtonWidget extends StatefulWidget {
|
||||
const AddProductButtonWidget({super.key});
|
||||
@@ -9,31 +13,61 @@ class AddProductButtonWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _AddProductButtonWidgetState extends State<AddProductButtonWidget> {
|
||||
late final DiaryCubit diaryCubit;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: () {}, // todo open modal for product add
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Ink(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
width: MediaQuery.of(context).size.width - 32,
|
||||
decoration: BoxDecoration(
|
||||
color: appTheme.blueA400,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(16),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Добавить',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
void initState() {
|
||||
super.initState();
|
||||
diaryCubit = context.read<DiaryCubit>();
|
||||
}
|
||||
|
||||
addProductInMeal(DiaryStateLoaded state, [int? portionId]) {
|
||||
return showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
context: context,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(12)),
|
||||
),
|
||||
isScrollControlled: true,
|
||||
builder: (context) => AddProductModal(
|
||||
state: state,
|
||||
diaryCubit: diaryCubit,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DiaryCubit, DiaryState>(
|
||||
builder: (context, state) {
|
||||
if (state is DiaryStateLoaded) {
|
||||
return InkWell(
|
||||
onTap: () => addProductInMeal(state),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Ink(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
width: MediaQuery.of(context).size.width - 32,
|
||||
decoration: BoxDecoration(
|
||||
color: appTheme.blueA400,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(16),
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'Добавить',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,220 +0,0 @@
|
||||
// import 'package:flutter/material.dart';
|
||||
//
|
||||
// class AddProductInMealWidget extends StatefulWidget {
|
||||
// const AddProductInMealWidget({super.key});
|
||||
//
|
||||
// @override
|
||||
// State<AddProductInMealWidget> createState() => _AddProductInMealWidgetState();
|
||||
// }
|
||||
//
|
||||
// class _AddProductInMealWidgetState extends State<AddProductInMealWidget> {
|
||||
// addProductInMeal(DiaryDayModel diaryDay, [int? portionId]) {
|
||||
// return showModalBottomSheet(
|
||||
// useRootNavigator: true,
|
||||
// context: context,
|
||||
// shape: RoundedRectangleBorder(
|
||||
// borderRadius: BorderRadius.vertical(top: Radius.circular(12)),
|
||||
// ),
|
||||
// isScrollControlled: true,
|
||||
// builder: (context) {
|
||||
// return StatefulBuilder(
|
||||
// builder: (BuildContext context, void Function(void Function()) setState) {
|
||||
// return Padding(
|
||||
// padding: const EdgeInsets.all(16) +
|
||||
// EdgeInsets.only(
|
||||
// bottom: MediaQuery.of(context).viewInsets.bottom,
|
||||
// ),
|
||||
// child: Column(
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
// children: [
|
||||
// Text(
|
||||
// 'Добавление блюда',
|
||||
// style: TextStyle(
|
||||
// fontSize: 20,
|
||||
// fontWeight: FontWeight.w600,
|
||||
// color: Color(0xFF323F4B),
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(height: 16),
|
||||
// Row(
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
// children: [
|
||||
// SizedBox(
|
||||
// width: MediaQuery.of(context).size.width * 0.8 - 32,
|
||||
// child: TypeAheadField(
|
||||
// controller: productNameController,
|
||||
// itemBuilder: (context, glossary) {
|
||||
// return Padding(
|
||||
// padding: const EdgeInsets.all(8.0),
|
||||
// child: Text(
|
||||
// glossary.name,
|
||||
// style: TextStyle(
|
||||
// height: 1,
|
||||
// fontSize: 16,
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// itemSeparatorBuilder: (context, index) => _divider(context),
|
||||
// onSelected: (newSelectedGlossary) async {
|
||||
// setState(() {
|
||||
// selectedGlossary = newSelectedGlossary;
|
||||
// productNameController.text = selectedGlossary!.name;
|
||||
// });
|
||||
// },
|
||||
// suggestionsCallback: (query) async {
|
||||
// if (query.length < 1) return [];
|
||||
// final suggestionsList = await diaryCubit.getGlossaryListByQuery(query);
|
||||
// return suggestionsList;
|
||||
// },
|
||||
// builder: (context, controller, focusNode) {
|
||||
// return CustomTextFormField(
|
||||
// controller: controller,
|
||||
// autofocus: true,
|
||||
// focusNode: focusNode,
|
||||
// hintText: 'Введите название продукта/блюда',
|
||||
// );
|
||||
// },
|
||||
// emptyBuilder: (context) {
|
||||
// return const SizedBox.shrink();
|
||||
// },
|
||||
// errorBuilder: (context, object) => Padding(
|
||||
// padding: const EdgeInsets.all(8.0),
|
||||
// child: Text('Нет подходящих вариантов'),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(width: 4),
|
||||
// SizedBox(
|
||||
// width: MediaQuery.of(context).size.width * 0.2 - 4,
|
||||
// child: CustomTextFormField(
|
||||
// controller: quantityController,
|
||||
// keyboardType: TextInputType.number,
|
||||
// hintText: selectedGlossary == null
|
||||
// ? '100'
|
||||
// : selectedGlossary!.grInPortion == 0
|
||||
// ? '100'
|
||||
// : '1',
|
||||
// suffixText: selectedGlossary == null
|
||||
// ? 'гр'
|
||||
// : selectedGlossary?.grInPortion == 0
|
||||
// ? 'гр'
|
||||
// : 'шт',
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// const SizedBox(height: 16),
|
||||
// Row(
|
||||
// children: [
|
||||
// if (portionId != null)
|
||||
// InkWell(
|
||||
// onTap: () {
|
||||
// diaryCubit.deleteProductFromMeal(
|
||||
// diaryId: diaryDay.id,
|
||||
// mealId: diaryDay.meals[currentSelectedMealNumber - 1].id,
|
||||
// portionId: portionId,
|
||||
// date: _selectedDay.toString(),
|
||||
// );
|
||||
// Navigator.of(context).pop();
|
||||
// },
|
||||
// borderRadius: BorderRadius.circular(20),
|
||||
// child: Ink(
|
||||
// width: 52,
|
||||
// height: 52,
|
||||
// decoration: BoxDecoration(
|
||||
// borderRadius: BorderRadius.circular(20),
|
||||
// color: Color(0xFFF6F6F6),
|
||||
// ),
|
||||
// child: Icon(
|
||||
// Icons.delete_outline_rounded,
|
||||
// color: Colors.red,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// if (portionId != null) const SizedBox(width: 8),
|
||||
// InkWell(
|
||||
// onTap: () {
|
||||
// if (portionId == null) {
|
||||
// diaryCubit.addProductToMeal(
|
||||
// diaryId: diaryDay.id,
|
||||
// mealId: diaryDay.meals[currentSelectedMealNumber - 1].id,
|
||||
// productName: productNameController.text,
|
||||
// portion: selectedGlossary == null
|
||||
// ? 'gr'
|
||||
// : selectedGlossary!.grInPortion == 0
|
||||
// ? 'gr'
|
||||
// : 'pcs',
|
||||
// quantity: int.parse(quantityController.text),
|
||||
// date: _selectedDay.toString(),
|
||||
// );
|
||||
// } else {
|
||||
// diaryCubit.updateProductInMeal(
|
||||
// diaryId: diaryDay.id,
|
||||
// mealId: diaryDay.meals[currentSelectedMealNumber - 1].id,
|
||||
// portionId: portionId,
|
||||
// productName: productNameController.text,
|
||||
// portion: selectedGlossary == null
|
||||
// ? 'gr'
|
||||
// : selectedGlossary!.grInPortion == 0
|
||||
// ? 'gr'
|
||||
// : 'pcs',
|
||||
// quantity: int.parse(quantityController.text),
|
||||
// date: _selectedDay.toString(),
|
||||
// );
|
||||
// }
|
||||
// Navigator.of(context).pop();
|
||||
// if (selectedGlossary == null) {
|
||||
// showModalBottomSheet(
|
||||
// isScrollControlled: true,
|
||||
// useRootNavigator: true,
|
||||
// context: context,
|
||||
// builder: (context) => Padding(
|
||||
// padding: EdgeInsets.only(
|
||||
// bottom: MediaQuery.of(context).viewInsets.bottom,
|
||||
// ),
|
||||
// child: GlossaryModerationRequestModalWidget(
|
||||
// productName: productNameController.text,
|
||||
// diaryCubit: diaryCubit,
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// },
|
||||
// borderRadius: BorderRadius.circular(20),
|
||||
// child: Ink(
|
||||
// width: MediaQuery.of(context).size.width - (portionId == null ? 32 : 92),
|
||||
// height: 52,
|
||||
// decoration: BoxDecoration(
|
||||
// borderRadius: BorderRadius.circular(20),
|
||||
// color: appTheme.blueA400,
|
||||
// ),
|
||||
// child: Center(
|
||||
// child: Text(
|
||||
// portionId == null ? 'Добавить' : 'Сохранить',
|
||||
// style: TextStyle(
|
||||
// fontSize: 18,
|
||||
// fontWeight: FontWeight.w600,
|
||||
// color: Colors.white,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return const Placeholder();
|
||||
// }
|
||||
// }
|
||||
234
lib/features/diary/presentation/widgets/add_product_modal.dart
Normal file
234
lib/features/diary/presentation/widgets/add_product_modal.dart
Normal file
@@ -0,0 +1,234 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_divider.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
|
||||
import 'package:eatvio_app/features/diary/models/diary_day_model.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_cubit.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/widgets/glossary_moderation_request_modal_widget.dart';
|
||||
import 'package:eatvio_app/features/glossary/models/glossary_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_typeahead/flutter_typeahead.dart';
|
||||
|
||||
class AddProductModal extends StatefulWidget {
|
||||
final Portion? portion;
|
||||
final DiaryStateLoaded state;
|
||||
final DiaryCubit diaryCubit;
|
||||
|
||||
const AddProductModal({
|
||||
super.key,
|
||||
this.portion,
|
||||
required this.state,
|
||||
required this.diaryCubit,
|
||||
});
|
||||
|
||||
@override
|
||||
State<AddProductModal> createState() => _AddProductModalState();
|
||||
}
|
||||
|
||||
class _AddProductModalState extends State<AddProductModal> {
|
||||
final productNameController = TextEditingController();
|
||||
final quantityController = TextEditingController();
|
||||
GlossaryModel? selectedGlossary;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.portion != null) {
|
||||
productNameController.text = widget.portion!.productName;
|
||||
quantityController.text = '${widget.portion!.quantity}';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return StatefulBuilder(
|
||||
builder: (BuildContext context, void Function(void Function()) setState) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16) +
|
||||
EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).viewInsets.bottom,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'Добавление блюда',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF323F4B),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.8 - 32,
|
||||
child: TypeAheadField(
|
||||
controller: productNameController,
|
||||
itemBuilder: (context, glossary) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
glossary.name,
|
||||
style: TextStyle(
|
||||
height: 1,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
itemSeparatorBuilder: (context, index) => CustomDivider(),
|
||||
onSelected: (newSelectedGlossary) async {
|
||||
setState(() {
|
||||
selectedGlossary = newSelectedGlossary;
|
||||
productNameController.text = selectedGlossary!.name;
|
||||
});
|
||||
},
|
||||
suggestionsCallback: (query) async {
|
||||
if (query.length < 1) return [];
|
||||
final suggestionsList = await widget.diaryCubit.getGlossaryListByQuery(query);
|
||||
return suggestionsList;
|
||||
},
|
||||
builder: (context, controller, focusNode) {
|
||||
return CustomTextFormField(
|
||||
controller: controller,
|
||||
autofocus: true,
|
||||
focusNode: focusNode,
|
||||
hintText: 'Введите название продукта/блюда',
|
||||
);
|
||||
},
|
||||
emptyBuilder: (context) {
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
errorBuilder: (context, object) => Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text('Нет подходящих вариантов'),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width * 0.2 - 4,
|
||||
child: CustomTextFormField(
|
||||
controller: quantityController,
|
||||
keyboardType: TextInputType.number,
|
||||
hintText: selectedGlossary == null
|
||||
? '100'
|
||||
: selectedGlossary!.grInPortion == 0
|
||||
? '100'
|
||||
: '1',
|
||||
suffixText: selectedGlossary == null
|
||||
? 'гр'
|
||||
: selectedGlossary?.grInPortion == 0
|
||||
? 'гр'
|
||||
: 'шт',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
if (widget.portion != null)
|
||||
InkWell(
|
||||
onTap: () {
|
||||
widget.diaryCubit.deleteProductFromMeal(
|
||||
diaryId: widget.state.diary.id,
|
||||
mealId: widget.state.selectedMeal,
|
||||
portionId: widget.portion!.id,
|
||||
);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Ink(
|
||||
width: 52,
|
||||
height: 52,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: Color(0xFFF6F6F6),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.delete_outline_rounded,
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (widget.portion != null) const SizedBox(width: 8),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
if (widget.portion == null) {
|
||||
widget.diaryCubit.addProductToMeal(
|
||||
diaryId: widget.state.diary.id,
|
||||
mealId: widget.state.selectedMeal,
|
||||
productName: productNameController.text,
|
||||
portion: selectedGlossary == null
|
||||
? 'gr'
|
||||
: selectedGlossary!.grInPortion == 0
|
||||
? 'gr'
|
||||
: 'pcs',
|
||||
quantity: int.parse(quantityController.text),
|
||||
);
|
||||
} else {
|
||||
widget.diaryCubit.updateProductInMeal(
|
||||
diaryId: widget.state.diary.id,
|
||||
mealId: widget.state.selectedMeal,
|
||||
portionId: widget.portion!.id,
|
||||
productName: productNameController.text,
|
||||
portion: selectedGlossary == null
|
||||
? 'gr'
|
||||
: selectedGlossary!.grInPortion == 0
|
||||
? 'gr'
|
||||
: 'pcs',
|
||||
quantity: int.parse(quantityController.text),
|
||||
);
|
||||
}
|
||||
Navigator.of(context).pop();
|
||||
if (selectedGlossary == null) {
|
||||
showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
useRootNavigator: true,
|
||||
context: context,
|
||||
builder: (context) => Padding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).viewInsets.bottom,
|
||||
),
|
||||
child: GlossaryModerationRequestModalWidget(
|
||||
productName: productNameController.text,
|
||||
diaryCubit: widget.diaryCubit,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Ink(
|
||||
width: MediaQuery.of(context).size.width - (widget.portion == null ? 32 : 92),
|
||||
height: 52,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: appTheme.blueA400,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
widget.portion == null ? 'Добавить' : 'Сохранить',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'package:eatvio_app/features/diary/presentation/widgets/add_product_butto
|
||||
import 'package:eatvio_app/features/diary/presentation/widgets/meal_button_widget.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/widgets/photo_gallery_widget.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/widgets/products_list_widget.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/widgets/time_of_meal_picker_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MealWidget extends StatefulWidget {
|
||||
@@ -42,10 +43,12 @@ class _MealWidgetState extends State<MealWidget> {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// TimeOfMealPickerWidget(), // TODO endpoint for save time of meal
|
||||
TimeOfMealPickerWidget(),
|
||||
const SizedBox(height: 12),
|
||||
ProductsListWidget(),
|
||||
const SizedBox(height: 12),
|
||||
AddProductButtonWidget(),
|
||||
const SizedBox(height: 12),
|
||||
PhotoGalleryWidget(),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -20,8 +20,15 @@ class PhotoGalleryWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _PhotoGalleryWidgetState extends State<PhotoGalleryWidget> {
|
||||
late final DiaryCubit diaryCubit;
|
||||
int currentSelectedPhotoIndex = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
diaryCubit = context.read<DiaryCubit>();
|
||||
}
|
||||
|
||||
showImagePicker(DiaryDayModel diaryDay) {
|
||||
showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
@@ -33,7 +40,7 @@ class _PhotoGalleryWidgetState extends State<PhotoGalleryWidget> {
|
||||
final picker = ImagePicker();
|
||||
XFile? image = await picker.pickImage(source: ImageSource.camera);
|
||||
if (image != null)
|
||||
context.read<DiaryCubit>().uploadPhotos(
|
||||
diaryCubit.uploadPhotos(
|
||||
files: [File(image.path)],
|
||||
diaryId: diaryDay.id,
|
||||
);
|
||||
@@ -52,10 +59,10 @@ class _PhotoGalleryWidgetState extends State<PhotoGalleryWidget> {
|
||||
final picker = ImagePicker();
|
||||
List<XFile>? images = await picker.pickMultiImage();
|
||||
if (images.isNotEmpty)
|
||||
context.read<DiaryCubit>().uploadPhotos(
|
||||
files: images.map((f) => File(f.path)).toList(),
|
||||
diaryId: diaryDay.id,
|
||||
);
|
||||
diaryCubit.uploadPhotos(
|
||||
files: images.map((f) => File(f.path)).toList(),
|
||||
diaryId: diaryDay.id,
|
||||
);
|
||||
},
|
||||
child: const Row(
|
||||
children: const [
|
||||
@@ -80,7 +87,8 @@ class _PhotoGalleryWidgetState extends State<PhotoGalleryWidget> {
|
||||
return BlocBuilder<DiaryCubit, DiaryState>(
|
||||
builder: (context, state) {
|
||||
if (state is DiaryStateLoaded) {
|
||||
if (state.diary.meals[state.selectedMeal].photos.isEmpty) {
|
||||
int mealIndex = state.selectedMeal - 1;
|
||||
if (state.diary.meals[mealIndex].photos.isEmpty) {
|
||||
return GestureDetector(
|
||||
onTap: () => showImagePicker(state.diary),
|
||||
child: SvgPicture.asset(
|
||||
@@ -99,7 +107,7 @@ class _PhotoGalleryWidgetState extends State<PhotoGalleryWidget> {
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: baseUrl + '/storage/' + state.diary.meals[state.selectedMeal].photos[currentSelectedPhotoIndex].path,
|
||||
imageUrl: baseUrl + '/storage/' + state.diary.meals[mealIndex].photos[currentSelectedPhotoIndex].path,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
@@ -110,13 +118,13 @@ class _PhotoGalleryWidgetState extends State<PhotoGalleryWidget> {
|
||||
elevation: 0,
|
||||
),
|
||||
onPressed: () async {
|
||||
await context.read<DiaryCubit>().deletePhoto(
|
||||
photo: state.diary.meals[state.selectedMeal].photos[currentSelectedPhotoIndex],
|
||||
await diaryCubit.deletePhoto(
|
||||
photo: state.diary.meals[mealIndex].photos[currentSelectedPhotoIndex],
|
||||
diaryId: state.diary.id,
|
||||
);
|
||||
setState(() {
|
||||
if (currentSelectedPhotoIndex == state.diary.meals[state.selectedMeal].photos.length - 1 && currentSelectedPhotoIndex != 0) {
|
||||
currentSelectedPhotoIndex = state.diary.meals[state.selectedMeal].photos.length - 2;
|
||||
if (currentSelectedPhotoIndex == state.diary.meals[mealIndex].photos.length - 1 && currentSelectedPhotoIndex != 0) {
|
||||
currentSelectedPhotoIndex = state.diary.meals[mealIndex].photos.length - 2;
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -136,8 +144,8 @@ class _PhotoGalleryWidgetState extends State<PhotoGalleryWidget> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
for (int i = 0; i < state.diary.meals[state.selectedMeal].photos.length + 1; i++) ...[
|
||||
if (i == state.diary.meals[state.selectedMeal].photos.length)
|
||||
for (int i = 0; i < state.diary.meals[mealIndex].photos.length + 1; i++) ...[
|
||||
if (i == state.diary.meals[mealIndex].photos.length)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8),
|
||||
child: InkWell(
|
||||
@@ -157,7 +165,7 @@ class _PhotoGalleryWidgetState extends State<PhotoGalleryWidget> {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (i < state.diary.meals[state.selectedMeal].photos.length)
|
||||
if (i < state.diary.meals[mealIndex].photos.length)
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
@@ -170,13 +178,13 @@ class _PhotoGalleryWidgetState extends State<PhotoGalleryWidget> {
|
||||
height: 52,
|
||||
width: 52,
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: baseUrl + '/storage/' + state.diary.meals[state.selectedMeal].photos[i].path,
|
||||
imageUrl: baseUrl + '/storage/' + state.diary.meals[mealIndex].photos[i].path,
|
||||
fit: BoxFit.fitWidth,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (i < state.diary.meals[state.selectedMeal].photos.length - 1) const SizedBox(width: 8),
|
||||
if (i < state.diary.meals[mealIndex].photos.length - 1) const SizedBox(width: 8),
|
||||
],
|
||||
],
|
||||
),
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import 'package:eatvio_app/features/diary/models/diary_day_model.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_cubit.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/widgets/add_product_modal.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class ProductWidget extends StatefulWidget {
|
||||
final String product, portion;
|
||||
final int quantity;
|
||||
final Portion portion;
|
||||
|
||||
const ProductWidget({
|
||||
super.key,
|
||||
required this.product,
|
||||
required this.quantity,
|
||||
required this.portion,
|
||||
});
|
||||
|
||||
@@ -16,17 +18,48 @@ class ProductWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ProductWidgetState extends State<ProductWidget> {
|
||||
late final DiaryCubit diaryCubit;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
diaryCubit = context.read<DiaryCubit>();
|
||||
}
|
||||
|
||||
updateProductInMeal(DiaryStateLoaded state, Portion portion) {
|
||||
return showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
context: context,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(12)),
|
||||
),
|
||||
isScrollControlled: true,
|
||||
builder: (context) => AddProductModal(
|
||||
state: state,
|
||||
portion: portion,
|
||||
diaryCubit: diaryCubit,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
onTap: () {}, // todo change product in meal
|
||||
trailing: Icon(Icons.more_vert_rounded),
|
||||
title: Text(widget.product),
|
||||
subtitle: Text('${widget.quantity} ${widget.portion == 'gr' ? 'гр' : 'шт'}'),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
tileColor: Color(0xFFF6FAFF),
|
||||
return BlocBuilder<DiaryCubit, DiaryState>(
|
||||
builder: (context, state) {
|
||||
if (state is DiaryStateLoaded) {
|
||||
return ListTile(
|
||||
onTap: () => updateProductInMeal(state, widget.portion),
|
||||
trailing: Icon(Icons.more_vert_rounded),
|
||||
title: Text(widget.portion.productName),
|
||||
subtitle: Text('${widget.portion.quantity} ${widget.portion == 'gr' ? 'гр' : 'шт'}'),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
tileColor: Color(0xFFF6FAFF),
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,16 +17,13 @@ class _ProductsListWidgetState extends State<ProductsListWidget> {
|
||||
return BlocBuilder<DiaryCubit, DiaryState>(
|
||||
builder: (BuildContext context, DiaryState state) {
|
||||
if (state is DiaryStateLoaded) {
|
||||
int mealIndex = state.selectedMeal - 1;
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
for (int i = 0; i < state.diary.meals[state.selectedMeal].portions.length; i++) ...[
|
||||
ProductWidget(
|
||||
product: state.diary.meals[state.selectedMeal].portions[i].productName,
|
||||
quantity: state.diary.meals[state.selectedMeal].portions[i].quantity,
|
||||
portion: state.diary.meals[state.selectedMeal].portions[i].portion,
|
||||
),
|
||||
i < state.diary.meals[state.selectedMeal].portions.length - 1 ? const SizedBox(height: 8) : const SizedBox.shrink(),
|
||||
for (int i = 0; i < state.diary.meals[mealIndex].portions.length; i++) ...[
|
||||
ProductWidget(portion: state.diary.meals[mealIndex].portions[i]),
|
||||
i < state.diary.meals[mealIndex].portions.length - 1 ? const SizedBox(height: 8) : const SizedBox.shrink(),
|
||||
],
|
||||
],
|
||||
);
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_divider.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_cubit.dart';
|
||||
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class TimeOfMealPickerWidget extends StatefulWidget {
|
||||
const TimeOfMealPickerWidget({super.key});
|
||||
@@ -11,10 +14,17 @@ class TimeOfMealPickerWidget extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _TimeOfMealPickerWidgetState extends State<TimeOfMealPickerWidget> {
|
||||
late final DiaryCubit diaryCubit;
|
||||
String time = "${DateTime.now().hour.toString().padLeft(2, '0')}:${DateTime.now().minute.toString().padLeft(2, '0')}";
|
||||
DateTime _time = DateTime.now();
|
||||
|
||||
showTimePicker() {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
diaryCubit = context.read<DiaryCubit>();
|
||||
}
|
||||
|
||||
showTimePicker(int diaryId) {
|
||||
showModalBottomSheet<void>(
|
||||
context: context,
|
||||
useRootNavigator: true,
|
||||
@@ -38,6 +48,10 @@ class _TimeOfMealPickerWidgetState extends State<TimeOfMealPickerWidget> {
|
||||
InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
diaryCubit.fillTime(
|
||||
diaryId: diaryId,
|
||||
time: '$time:00',
|
||||
);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Ink(
|
||||
@@ -67,50 +81,65 @@ class _TimeOfMealPickerWidgetState extends State<TimeOfMealPickerWidget> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
CustomDivider(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
return BlocConsumer<DiaryCubit, DiaryState>(
|
||||
listener: (BuildContext context, DiaryState state) {
|
||||
if (state is DiaryStateLoaded) {
|
||||
setState(() {
|
||||
time = state.diary.meals[state.selectedMeal - 1].time;
|
||||
_time = DateTime.parse('0000-00-00 ${state.diary.meals[state.selectedMeal - 1].time}');
|
||||
});
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
if (state is DiaryStateLoaded) {
|
||||
return Column(
|
||||
children: [
|
||||
Text(
|
||||
'Время приема пищи',
|
||||
style: TextStyle(
|
||||
color: Color(0xFF323F4B),
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () => showTimePicker(),
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
child: Ink(
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
color: Color(0xFFF1F2F6),
|
||||
),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Text(
|
||||
time,
|
||||
CustomDivider(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'Время приема пищи',
|
||||
style: TextStyle(
|
||||
color: Color(0xFF6D6F71),
|
||||
fontSize: 17,
|
||||
color: Color(0xFF323F4B),
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () => showTimePicker(state.diary.id),
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
child: Ink(
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
color: Color(0xFFF1F2F6),
|
||||
),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Text(
|
||||
time,
|
||||
style: TextStyle(
|
||||
color: Color(0xFF6D6F71),
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
CustomDivider(),
|
||||
],
|
||||
),
|
||||
),
|
||||
CustomDivider(),
|
||||
],
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user