diff --git a/lib/features/create_diet/presentation/widgets/add_meal_widget.dart b/lib/features/create_diet/presentation/widgets/add_meal_widget.dart index a8eb36d5..bfe5d823 100644 --- a/lib/features/create_diet/presentation/widgets/add_meal_widget.dart +++ b/lib/features/create_diet/presentation/widgets/add_meal_widget.dart @@ -59,43 +59,47 @@ class _AddMealWidgetState extends State { Row( mainAxisSize: MainAxisSize.min, children: [ - SizedBox( - width: MediaQuery.of(context).size.width * 0.8 - 32, - child: CustomTextFormField( - controller: productNameController, - autofocus: true, - hintText: 'Введите название продукта/блюда', - onChanged: (query) { - EasyDebounce.debounce('glossary-search', const Duration(milliseconds: 250), () async { - selectedGlossary = null; - if (query.isEmpty) { - glossariesList = []; + Expanded( + flex: 2, + child: SizedBox( + child: CustomTextFormField( + controller: productNameController, + autofocus: true, + hintText: 'Введите название продукта/блюда', + onChanged: (query) { + EasyDebounce.debounce('glossary-search', const Duration(milliseconds: 250), () async { selectedGlossary = null; + if (query.isEmpty) { + glossariesList = []; + selectedGlossary = null; + setState(() {}); + return; + } + glossariesList = await widget.createDietCubit.getGlossaryListByQuery(query); setState(() {}); - return; - } - glossariesList = await widget.createDietCubit.getGlossaryListByQuery(query); - setState(() {}); - }); - }, + }); + }, + ), ), ), 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 - ? 'гр' - : 'шт', + Expanded( + flex: 1, + child: SizedBox( + child: CustomTextFormField( + controller: quantityController, + keyboardType: TextInputType.number, + hintText: selectedGlossary == null + ? '100' + : selectedGlossary!.grInPortion == 0 + ? '100' + : '1', + suffixText: selectedGlossary == null + ? 'гр' + : selectedGlossary?.grInPortion == 0 + ? 'гр' + : 'шт', + ), ), ), ], @@ -149,17 +153,19 @@ class _AddMealWidgetState extends State { ), ), if (widget.portionIndex != null) const SizedBox(width: 8), - InkWell( - onTap: addPortion, - borderRadius: BorderRadius.circular(20), - child: Ink( - width: MediaQuery.of(context).size.width - (widget.portionIndex == null ? 32 : 92), - height: 52, - decoration: BoxDecoration(borderRadius: BorderRadius.circular(20), color: appTheme.blueA400), - child: Center( - child: Text( - widget.portionIndex == null ? 'Добавить' : 'Сохранить', - style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Colors.white), + Expanded( + child: InkWell( + onTap: addPortion, + borderRadius: BorderRadius.circular(20), + child: Ink( + width: MediaQuery.of(context).size.width - (widget.portionIndex == null ? 32 : 92), + height: 52, + decoration: BoxDecoration(borderRadius: BorderRadius.circular(20), color: appTheme.blueA400), + child: Center( + child: Text( + widget.portionIndex == null ? 'Добавить' : 'Сохранить', + style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Colors.white), + ), ), ), ), diff --git a/lib/features/diary/presentation/widgets/add_product_modal.dart b/lib/features/diary/presentation/widgets/add_product_modal.dart index a0895bf9..611652cf 100644 --- a/lib/features/diary/presentation/widgets/add_product_modal.dart +++ b/lib/features/diary/presentation/widgets/add_product_modal.dart @@ -70,42 +70,46 @@ class _AddProductModalState extends State { Row( mainAxisSize: MainAxisSize.min, children: [ - SizedBox( - width: MediaQuery.of(context).size.width * 0.76 - 32, - child: CustomTextFormField( - controller: productNameController, - autofocus: true, - hintText: 'Введите название продукта/блюда', - onChanged: (query) { - EasyDebounce.debounce('glossary-search', const Duration(milliseconds: 250), () async { - selectedGlossary = null; - if (query.isEmpty) { - glossariesList = []; + Expanded( + flex: 2, + child: SizedBox( + child: CustomTextFormField( + controller: productNameController, + autofocus: true, + hintText: 'Введите название продукта/блюда', + onChanged: (query) { + EasyDebounce.debounce('glossary-search', const Duration(milliseconds: 250), () async { + selectedGlossary = null; + if (query.isEmpty) { + glossariesList = []; + setState(() {}); + return; + } + glossariesList = await widget.diaryCubit.getGlossaryListByQuery(query); setState(() {}); - return; - } - glossariesList = await widget.diaryCubit.getGlossaryListByQuery(query); - setState(() {}); - }); - }, + }); + }, + ), ), ), const SizedBox(width: 4), - SizedBox( - width: MediaQuery.of(context).size.width * 0.24 - 4, - child: CustomTextFormField( - controller: quantityController, - keyboardType: TextInputType.number, - hintText: selectedGlossary == null - ? '100' - : selectedGlossary!.grInPortion == 0 - ? '100' - : '1', - suffixText: selectedGlossary == null - ? 'гр' - : selectedGlossary?.grInPortion == 0 - ? 'гр' - : 'шт', + Expanded( + flex: 1, + child: SizedBox( + child: CustomTextFormField( + controller: quantityController, + keyboardType: TextInputType.number, + hintText: selectedGlossary == null + ? '100' + : selectedGlossary!.grInPortion == 0 + ? '100' + : '1', + suffixText: selectedGlossary == null + ? 'гр' + : selectedGlossary?.grInPortion == 0 + ? 'гр' + : 'шт', + ), ), ), ], @@ -168,66 +172,68 @@ class _AddProductModalState extends State { ), ), if (widget.portion != null) const SizedBox(width: 8), - InkWell( - onTap: () { - // Автоматически выбираем первый элемент, если текст точно совпадает - if (selectedGlossary == null && - glossariesList.isNotEmpty && - productNameController.text.trim().toLowerCase() == glossariesList[0].name.toLowerCase()) { - selectedGlossary = glossariesList[0]; - } + Expanded( + child: InkWell( + onTap: () { + // Автоматически выбираем первый элемент, если текст точно совпадает + if (selectedGlossary == null && + glossariesList.isNotEmpty && + productNameController.text.trim().toLowerCase() == glossariesList[0].name.toLowerCase()) { + selectedGlossary = glossariesList[0]; + } - 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), - productNutritionalValueId: selectedGlossary?.id, - ); - } 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), - productNutritionalValueId: selectedGlossary?.id, - portionState: widget.portion!.portionState, - ); - } - Navigator.of(context).pop(); - if (selectedGlossary == null && _previousProductName != productNameController.text) { - 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), + 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), + productNutritionalValueId: selectedGlossary?.id, + ); + } 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), + productNutritionalValueId: selectedGlossary?.id, + portionState: widget.portion!.portionState, + ); + } + Navigator.of(context).pop(); + if (selectedGlossary == null && _previousProductName != productNameController.text) { + 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: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Colors.white), ), - ); - } - }, - 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: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Colors.white), ), ), ),