From ca385118d1df7ac1e0a9147f2cae63f6c501f161 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 20 Mar 2024 15:27:21 +0300 Subject: [PATCH] feat(diary): Moderation send dialog added to the screen --- .../bloc/diary_edit_event.dart | 17 ++++ .../diary_edit_screen/diary_edit_screen.dart | 88 +++++++++++++++++++ 2 files changed, 105 insertions(+) diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_event.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_event.dart index b80acf01..256cfb53 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_event.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_event.dart @@ -120,3 +120,20 @@ class FinishDay extends DiaryEditEvent { @override List get props => []; } + +class SendModeration extends DiaryEditEvent { + SendModeration( + {required this.name, + required this.energyOn100gr, + required this.proteinsOn100gr, + required this.fatsOn100gr, + required this.carbohydratesOn100gr}); + String name; + String energyOn100gr; + String proteinsOn100gr; + String fatsOn100gr; + String carbohydratesOn100gr; + @override + List get props => + [name, energyOn100gr, proteinsOn100gr, fatsOn100gr, carbohydratesOn100gr]; +} diff --git a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart index 6b5892bd..ac02cfe6 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -342,6 +342,15 @@ class DiaryEditScreen extends StatelessWidget { }), ), SizedBox(height: 20.v), + if (state.moderationExpanded) + Padding( + padding: EdgeInsets.symmetric(horizontal: 10.h), + child: GestureDetector( + onTap: () => openCaloriesDialog(context), + child: Text("Отправить на модерацию"), + ), + ), + SizedBox(height: 20.v), Padding( padding: EdgeInsets.symmetric(horizontal: 10.h), child: Row( @@ -428,6 +437,85 @@ class DiaryEditScreen extends StatelessWidget { )); } + openCaloriesDialog(BuildContext context) { + String name = ''; + String energyOn100gr = ''; + String proteinsOn100gr = ''; + String fatsOn100gr = ''; + String carbohydratesOn100gr = ''; + + showDialog( + context: context, + builder: (BuildContext dialogContext) { + return AlertDialog( + title: Text('Введите информацию о продукте'), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + TextFormField( + onChanged: (value) { + name = value; + }, + decoration: InputDecoration(hintText: 'Название'), + ), + TextFormField( + onChanged: (value) { + energyOn100gr = value; + }, + keyboardType: TextInputType.number, + decoration: InputDecoration( + hintText: 'Энергетическая ценность на 100г'), + ), + TextFormField( + onChanged: (value) { + proteinsOn100gr = value; + }, + keyboardType: TextInputType.number, + decoration: InputDecoration(hintText: 'Белки на 100г'), + ), + TextFormField( + onChanged: (value) { + fatsOn100gr = value; + }, + keyboardType: TextInputType.number, + decoration: InputDecoration(hintText: 'Жиры на 100г'), + ), + TextFormField( + onChanged: (value) { + carbohydratesOn100gr = value; + }, + keyboardType: TextInputType.number, + decoration: InputDecoration(hintText: 'Углеводы на 100г'), + ), + ], + ), + actions: [ + TextButton( + onPressed: () { + Navigator.of(dialogContext) + .pop(); // Dismiss the dialog on Cancel button press + }, + child: Text('Отмена'), + ), + TextButton( + onPressed: () { + // Call function to send moderation with the entered values + context.read().add(SendModeration( + name: name, + energyOn100gr: energyOn100gr, + proteinsOn100gr: proteinsOn100gr, + fatsOn100gr: fatsOn100gr, + carbohydratesOn100gr: carbohydratesOn100gr)); + Navigator.of(dialogContext).pop(); // Dismiss the dialog + }, + child: Text('Отправить'), + ), + ], + ); + }, + ); + } + changeSatiety(BuildContext context, int satiety) { return () { context.read().add(ChangeSatiety(satiety));