feat(diary): Moderation fields refactored. TEst re now passed

This commit is contained in:
2024-03-20 16:35:25 +03:00
parent ca385118d1
commit 89a9918ea5
2 changed files with 72 additions and 51 deletions

View File

@@ -465,9 +465,10 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
.toList(), .toList(),
); );
if (event.input.length > 3) { if (event.input.length > 2) {
updatedState = updatedState.copyWith( updatedState = updatedState.copyWith(moderationExpanded: true);
moderationExpanded: !currentState.moderationExpanded); } else {
updatedState = updatedState.copyWith(moderationExpanded: false);
} }
emit(updatedState); // Emit the updated state emit(updatedState); // Emit the updated state

View File

@@ -1,3 +1,5 @@
// ignore_for_file: unused_local_variable
import 'bloc/diary_edit_bloc.dart'; import 'bloc/diary_edit_bloc.dart';
import 'models/diary_edit_model.dart'; import 'models/diary_edit_model.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -444,6 +446,26 @@ class DiaryEditScreen extends StatelessWidget {
String fatsOn100gr = ''; String fatsOn100gr = '';
String carbohydratesOn100gr = ''; 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( showDialog(
context: context, context: context,
builder: (BuildContext dialogContext) { builder: (BuildContext dialogContext) {
@@ -452,70 +474,68 @@ class DiaryEditScreen extends StatelessWidget {
content: Column( content: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
TextFormField( CustomTextFormField(
onChanged: (value) { hintText: "Название",
name = value; onChanged: onNameChanged,
},
decoration: InputDecoration(hintText: 'Название'),
), ),
TextFormField( SizedBox(height: 10.v),
onChanged: (value) { CustomTextFormField(
energyOn100gr = value; onChanged: onEnergyChanged,
}, hintText: "Энергетическая ценность на 100",
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'Энергетическая ценность на 100г'),
), ),
TextFormField( SizedBox(height: 10.v),
onChanged: (value) { CustomTextFormField(
proteinsOn100gr = value; hintText: "Белки на 100г",
}, onChanged: onProteinsChanged,
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
decoration: InputDecoration(hintText: 'Белки на 100г'),
), ),
TextFormField( SizedBox(height: 10.v),
onChanged: (value) { CustomTextFormField(
fatsOn100gr = value; hintText: "Жиры на 100г",
}, onChanged: onFatsChanged,
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
decoration: InputDecoration(hintText: 'Жиры на 100г'),
), ),
TextFormField( SizedBox(height: 10.v),
onChanged: (value) { CustomTextFormField(
carbohydratesOn100gr = value; hintText: "Углеводы на 100г",
}, onChanged: onCarbohydratesChanged,
keyboardType: TextInputType.number, 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('Отправить'),
),
],
); );
}, },
); );
} }
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<DiaryEditBloc>().add(SendModeration(
name: name,
energyOn100gr: energyOn100gr,
proteinsOn100gr: proteinsOn100gr,
fatsOn100gr: fatsOn100gr,
carbohydratesOn100gr: carbohydratesOn100gr));
Navigator.of(dialogContext).pop(); // Dismiss the dialog
};
}
changeSatiety(BuildContext context, int satiety) { changeSatiety(BuildContext context, int satiety) {
return () { return () {
context.read<DiaryEditBloc>().add(ChangeSatiety(satiety)); context.read<DiaryEditBloc>().add(ChangeSatiety(satiety));