forked from eatvio/eatvio_app
feat(diary): Moderation fields refactored. TEst re now passed
This commit is contained in:
@@ -465,9 +465,10 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
||||
.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
|
||||
|
||||
@@ -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: <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) {
|
||||
return () {
|
||||
context.read<DiaryEditBloc>().add(ChangeSatiety(satiety));
|
||||
|
||||
Reference in New Issue
Block a user