feat(diary): New state variable for moderation button control

This commit is contained in:
2024-03-20 14:31:21 +03:00
parent 37c7a41efa
commit 5681a8df1c
3 changed files with 13 additions and 7 deletions

View File

@@ -74,6 +74,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
currentMeal: currentState.currentMeal,
wakeupExpanded: currentState.wakeupExpanded,
moodExpanded: currentState.moodExpanded,
moderationExpanded: currentState.moderationExpanded,
token: currentState.token,
meals: currentState.meals,
wakeupController: currentState.wakeupController,
@@ -97,6 +98,7 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
id: 1, title: "Прием пищи 1", isSelected: true),
wakeupExpanded: true,
moodExpanded: true,
moderationExpanded: false,
token: token,
meals: diary['meals'],
portions: diary['meals'][0]['portions'],
@@ -267,7 +269,6 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
body: json.encode(credentials),
encoding: utf8,
);
print(response.body);
return response;
}
@@ -464,9 +465,12 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
.toList(),
);
if (event.input.length > 3) {
updatedState = updatedState.copyWith(
moderationExpanded: !currentState.moderationExpanded);
}
emit(updatedState); // Emit the updated state
} else {
print("Ошибка в декодировании ответа из API");
}
}
}
@@ -494,7 +498,6 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
final updatedState = currentState.copyWith(portions: updatedPortions);
emit(updatedState); // Emit the updated state
print("removed");
}
}
}
@@ -513,13 +516,10 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
encoding: utf8,
);
print(response.body);
return response;
}
Future<void> _finishDay(FinishDay event, Emitter<DiaryEditState> emit) async {
print("imageUrl");
if (state is DiaryEditLoadedState) {
var currentState = state as DiaryEditLoadedState;

View File

@@ -35,6 +35,7 @@ class DiaryEditLoadedState extends DiaryEditState {
this.currentMeal,
required this.diaryId,
required this.selectedSatiety,
required this.moderationExpanded,
required this.wakeupExpanded,
required this.moodExpanded})
: super(diaryEditModelObj: null);
@@ -56,6 +57,7 @@ class DiaryEditLoadedState extends DiaryEditState {
int selectedSatiety;
int diaryId;
bool wakeupExpanded;
bool moderationExpanded;
bool moodExpanded;
@override
List<Object?> get props => [
@@ -75,6 +77,7 @@ class DiaryEditLoadedState extends DiaryEditState {
diaryId,
wakeupExpanded,
moodExpanded,
moderationExpanded,
currentMeal
];
DiaryEditLoadedState copyWith({
@@ -95,6 +98,7 @@ class DiaryEditLoadedState extends DiaryEditState {
int? selectedSatiety,
int? diaryId,
bool? wakeupExpanded,
bool? moderationExpanded,
bool? moodExpanded,
}) {
return DiaryEditLoadedState(
@@ -117,6 +121,7 @@ class DiaryEditLoadedState extends DiaryEditState {
diaryId: diaryId ?? this.diaryId,
currentMeal: currentMeal ?? this.currentMeal,
wakeupExpanded: wakeupExpanded ?? this.wakeupExpanded,
moderationExpanded: moderationExpanded ?? this.moderationExpanded,
moodExpanded: moodExpanded ?? this.moodExpanded);
}
}

View File

@@ -26,6 +26,7 @@ void main() {
autocompleteList: [],
portions: [],
wakeupExpanded: false,
moderationExpanded: false,
moodExpanded: false);
await tester.pumpWidget(