feat(diary): Moderation send dialog added to the screen

This commit is contained in:
2024-03-20 15:27:21 +03:00
parent 5681a8df1c
commit ca385118d1
2 changed files with 105 additions and 0 deletions

View File

@@ -120,3 +120,20 @@ class FinishDay extends DiaryEditEvent {
@override
List<Object?> 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<Object?> get props =>
[name, energyOn100gr, proteinsOn100gr, fatsOn100gr, carbohydratesOn100gr];
}

View File

@@ -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: <Widget>[
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<DiaryEditBloc>().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<DiaryEditBloc>().add(ChangeSatiety(satiety));