diff --git a/lib/features/recipes/presentation/widgets/ingredients_widget.dart b/lib/features/recipes/presentation/widgets/ingredients_widget.dart index c8744492..e1ac4748 100644 --- a/lib/features/recipes/presentation/widgets/ingredients_widget.dart +++ b/lib/features/recipes/presentation/widgets/ingredients_widget.dart @@ -15,6 +15,9 @@ class IngredientsWidget extends StatefulWidget { class _IngredientsWidgetState extends State { late final CreateRecipeCubit createRecipeCubit; + final nameController = TextEditingController(); + final gramsController = TextEditingController(); + final pcsController = TextEditingController(); @override void initState() { @@ -80,121 +83,122 @@ class _IngredientsWidgetState extends State { ], ), ListTile( - onTap: () => showModalBottomSheet( - useRootNavigator: true, - context: context, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.vertical(top: Radius.circular(12)), - ), - isScrollControlled: true, - builder: (context) { - final nameController = TextEditingController(); - final grammsContorller = TextEditingController(); - final pcsController = TextEditingController(); - - return StatefulBuilder( - builder: (BuildContext context, void Function(void Function()) setStateInner) { - 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), + onTap: () { + nameController.clear(); + gramsController.clear(); + pcsController.clear(); + 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()) setStateInner) { + return Padding( + padding: const EdgeInsets.all(16) + + EdgeInsets.only( + bottom: MediaQuery.of(context).viewInsets.bottom, ), - ), - const SizedBox(height: 16), - SizedBox( - width: MediaQuery.of(context).size.width - 32, - child: CustomTextFormField( - autofocus: true, - controller: nameController, - hintText: 'Введите название продукта', - onChanged: (query) {}, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + 'Добавление ингредиента', + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.w600, + color: Color(0xFF323F4B), + ), ), - ), - const SizedBox(height: 8), - Row( - children: [ - SizedBox( - width: MediaQuery.of(context).size.width / 2 - 20, - child: CustomTextFormField( - enabled: pcsController.text.isEmpty ? true : false, - keyboardType: TextInputType.number, - controller: grammsContorller, - hintText: pcsController.text.isEmpty ? '100' : null, - suffixText: 'гр', - onChanged: (value) { - setStateInner(() {}); - }, - ), - ), - const SizedBox(width: 8), - SizedBox( - width: MediaQuery.of(context).size.width / 2 - 20, - child: CustomTextFormField( - enabled: grammsContorller.text.isEmpty ? true : false, - keyboardType: TextInputType.number, - controller: pcsController, - onChanged: (value) { - setStateInner(() {}); - }, - hintText: grammsContorller.text.isEmpty ? '1' : null, - suffixText: 'шт', - ), - ), - ], - ), - const SizedBox(height: 12), - InkWell( - onTap: () { - if (nameController.text.isNotEmpty && (pcsController.text.isNotEmpty || grammsContorller.text.isNotEmpty)) { - createRecipeCubit.addIngredient( - IngredientEntity( - name: nameController.text, - unit: grammsContorller.text.isEmpty ? pcsController.text : grammsContorller.text, - portion: grammsContorller.text.isEmpty ? 'pcs' : 'gr', - ), - ); - Navigator.of(context).pop(); - setState(() {}); - } - }, - borderRadius: BorderRadius.circular(20), - child: Ink( + const SizedBox(height: 16), + SizedBox( width: MediaQuery.of(context).size.width - 32, - height: 52, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(20), - color: appTheme.blueA400, + child: CustomTextFormField( + autofocus: true, + controller: nameController, + hintText: 'Введите название продукта', + onChanged: (query) {}, ), - child: Center( - child: Text( - 'Добавить', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.w600, - color: Colors.white, + ), + const SizedBox(height: 8), + Row( + children: [ + SizedBox( + width: MediaQuery.of(context).size.width / 2 - 20, + child: CustomTextFormField( + enabled: pcsController.text.isEmpty ? true : false, + keyboardType: TextInputType.number, + controller: gramsController, + hintText: pcsController.text.isEmpty ? '100' : null, + suffixText: 'гр', + onChanged: (value) { + setStateInner(() {}); + }, + ), + ), + const SizedBox(width: 8), + SizedBox( + width: MediaQuery.of(context).size.width / 2 - 20, + child: CustomTextFormField( + enabled: gramsController.text.isEmpty ? true : false, + keyboardType: TextInputType.number, + controller: pcsController, + onChanged: (value) { + setStateInner(() {}); + }, + hintText: gramsController.text.isEmpty ? '1' : null, + suffixText: 'шт', + ), + ), + ], + ), + const SizedBox(height: 12), + InkWell( + onTap: () { + if (nameController.text.isNotEmpty && (pcsController.text.isNotEmpty || gramsController.text.isNotEmpty)) { + createRecipeCubit.addIngredient( + IngredientEntity( + name: nameController.text, + unit: gramsController.text.isEmpty ? pcsController.text : gramsController.text, + portion: gramsController.text.isEmpty ? 'pcs' : 'gr', + ), + ); + Navigator.of(context).pop(); + setState(() {}); + } + }, + borderRadius: BorderRadius.circular(20), + child: Ink( + width: MediaQuery.of(context).size.width - 32, + height: 52, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(20), + color: appTheme.blueA400, + ), + child: Center( + child: Text( + 'Добавить', + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.w600, + color: Colors.white, + ), ), ), ), ), - ), - ], - ), - ); - }, - ); - }, - ), + ], + ), + ); + }, + ); + }, + ); + }, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ),