From 89a9918ea5f74568cdb0df10842107f6ea720f20 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 20 Mar 2024 16:35:25 +0300 Subject: [PATCH] feat(diary): Moderation fields refactored. TEst re now passed --- .../bloc/diary_edit_bloc.dart | 7 +- .../diary_edit_screen/diary_edit_screen.dart | 116 ++++++++++-------- 2 files changed, 72 insertions(+), 51 deletions(-) diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart index ae978ad9..03366095 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart @@ -465,9 +465,10 @@ class DiaryEditBloc extends Bloc { .toList(), ); - if (event.input.length > 3) { - updatedState = updatedState.copyWith( - moderationExpanded: !currentState.moderationExpanded); + if (event.input.length > 2) { + updatedState = updatedState.copyWith(moderationExpanded: true); + } else { + updatedState = updatedState.copyWith(moderationExpanded: false); } emit(updatedState); // Emit the updated state 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 ac02cfe6..2c50efb9 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -1,3 +1,5 @@ +// ignore_for_file: unused_local_variable + import 'bloc/diary_edit_bloc.dart'; import 'models/diary_edit_model.dart'; import 'package:flutter/material.dart'; @@ -444,6 +446,26 @@ class DiaryEditScreen extends StatelessWidget { String fatsOn100gr = ''; String carbohydratesOn100gr = ''; + void onNameChanged(String value) { + name = value; + } + + void onEnergyChanged(String value) { + energyOn100gr = value; + } + + void onProteinsChanged(String value) { + proteinsOn100gr = value; + } + + void onFatsChanged(String value) { + fatsOn100gr = value; + } + + void onCarbohydratesChanged(String value) { + carbohydratesOn100gr = value; + } + showDialog( context: context, builder: (BuildContext dialogContext) { @@ -452,70 +474,68 @@ class DiaryEditScreen extends StatelessWidget { content: Column( mainAxisSize: MainAxisSize.min, children: [ - TextFormField( - onChanged: (value) { - name = value; - }, - decoration: InputDecoration(hintText: 'Название'), + CustomTextFormField( + hintText: "Название", + onChanged: onNameChanged, ), - TextFormField( - onChanged: (value) { - energyOn100gr = value; - }, + SizedBox(height: 10.v), + CustomTextFormField( + onChanged: onEnergyChanged, + hintText: "Энергетическая ценность на 100", keyboardType: TextInputType.number, - decoration: InputDecoration( - hintText: 'Энергетическая ценность на 100г'), ), - TextFormField( - onChanged: (value) { - proteinsOn100gr = value; - }, + SizedBox(height: 10.v), + CustomTextFormField( + hintText: "Белки на 100г", + onChanged: onProteinsChanged, keyboardType: TextInputType.number, - decoration: InputDecoration(hintText: 'Белки на 100г'), ), - TextFormField( - onChanged: (value) { - fatsOn100gr = value; - }, + SizedBox(height: 10.v), + CustomTextFormField( + hintText: "Жиры на 100г", + onChanged: onFatsChanged, keyboardType: TextInputType.number, - decoration: InputDecoration(hintText: 'Жиры на 100г'), ), - TextFormField( - onChanged: (value) { - carbohydratesOn100gr = value; - }, + SizedBox(height: 10.v), + CustomTextFormField( + hintText: "Углеводы на 100г", + onChanged: onCarbohydratesChanged, 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('Отправить'), - ), - ], ); }, ); } + popDialog(BuildContext dialogContext) { + return () { + Navigator.of(dialogContext) + .pop(); // Dismiss the dialog on Cancel button press + }; + } + + sendToModeration( + BuildContext context, + String name, + String energyOn100gr, + String proteinsOn100gr, + String fatsOn100gr, + String carbohydratesOn100gr, + BuildContext dialogContext) { + return () { + // 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 + }; + } + changeSatiety(BuildContext context, int satiety) { return () { context.read().add(ChangeSatiety(satiety));