From a6ab577d20151ded646d13da90478f3f7736ffe5 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Thu, 15 Feb 2024 16:02:13 +0300 Subject: [PATCH] feat(diary) Made an event expanded list display for mood --- .../bloc/diary_edit_bloc.dart | 18 ++- .../bloc/diary_edit_event.dart | 10 +- .../diary_edit_screen/diary_edit_screen.dart | 116 ++++++++++-------- 3 files changed, 85 insertions(+), 59 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 bd114b8e..c460b0d1 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 @@ -16,8 +16,9 @@ part 'diary_edit_state.dart'; class DiaryEditBloc extends Bloc { DiaryEditBloc(DiaryEditState initialState) : super(initialState) { on(_onInitialize); - on(_changeSatiety); + on(_changeSatiety); on(_changeMood); + on(_toggleMood); } Future _onInitialize( @@ -94,11 +95,12 @@ class DiaryEditBloc extends Bloc { }*/ Future _changeSatiety( - SatietyEvent event, Emitter emit) async { + ChangeSatiety event, Emitter emit) async { if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; emit(currentState.copyWith(selectedSatiety: event.selectedElement)); currentState.selectedSatiety = event.selectedElement; + print(currentState.selectedSatiety); } } @@ -106,8 +108,20 @@ class DiaryEditBloc extends Bloc { MoodEvent event, Emitter emit) async { if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; + emit(currentState.copyWith(selectedMood: event.selectedElement)); currentState.selectedMood = event.selectedElement; } } + + FutureOr _toggleMood( + ToggleMoodExpandedEvent event, Emitter emit) { + if (state is DiaryEditLoadedState) { + var currentState = state as DiaryEditLoadedState; + + emit(currentState.copyWith(moodExpanded: !currentState.moodExpanded)); + currentState.moodExpanded = !currentState.moodExpanded; + print(currentState.moodExpanded); + } + } } diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_event.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_event.dart index d88fead6..47c8994f 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_event.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_event.dart @@ -15,8 +15,8 @@ class DiaryEditInitialEvent extends DiaryEditEvent { List get props => []; } -class SatietyEvent extends DiaryEditEvent { - SatietyEvent(this.selectedElement); +class ChangeSatiety extends DiaryEditEvent { + ChangeSatiety(this.selectedElement); final int selectedElement; @override @@ -30,4 +30,8 @@ class MoodEvent extends DiaryEditEvent { @override List get props => [selectedElement]; } -//class ToggleWakeupExpandedEvent extends DiaryEditEvent {} + +class ToggleMoodExpandedEvent extends DiaryEditEvent { + @override + List get props => []; +} 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 795a4a63..469c9d1c 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -83,7 +83,7 @@ class DiaryEditScreen extends StatelessWidget { SizedBox(height: 20.v), _buildMood(context, state), SizedBox(height: 30.v), - _buildHeaderColumn(context), + _buildNutritionChart(context), SizedBox(height: 30.v), _buildComment(context, state), ], @@ -280,56 +280,64 @@ class DiaryEditScreen extends StatelessWidget { style: CustomTextStyles.bodyMediumBlack900, ), SizedBox(height: 15.v), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text("😭"), - ScaleElement( - color: Colors.red, - isSelected: state.selectedSatiety == 0, - onTap: () { - context.read().add(SatietyEvent(0)); - }, - ), - ScaleElement( - color: Colors.orange, - isSelected: state.selectedSatiety == 1, - onTap: () { - context.read().add(SatietyEvent(1)); - }, - ), - ScaleElement( - color: Colors.yellow, - isSelected: state.selectedSatiety == 2, - onTap: () { - context.read().add(SatietyEvent(2)); - }, - ), - ScaleElement( - color: Colors.lime, - isSelected: state.selectedSatiety == 3, - onTap: () { - context.read().add(SatietyEvent(3)); - }, - ), - ScaleElement( - color: Colors.lightGreen, - isSelected: state.selectedSatiety == 4, - onTap: () { - context.read().add(SatietyEvent(4)); - }, - ), - ScaleElement( - color: Colors.green, - isSelected: state.selectedSatiety == 5, - onTap: () { - context.read().add(SatietyEvent(5)); - }, - ), - Text("😊"), - // Остальные элементы шкалы - ], - ), + BlocBuilder( + builder: (context, state) { + if (state is DiaryEditLoadedState) { + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text("😭"), + ScaleElement( + color: Colors.red, + isSelected: state.selectedSatiety == 0, + onTap: () { + context.read().add(ChangeSatiety(0)); + }, + ), + ScaleElement( + color: Colors.orange, + isSelected: state.selectedSatiety == 1, + onTap: () { + context.read().add(ChangeSatiety(1)); + }, + ), + ScaleElement( + color: Colors.yellow, + isSelected: state.selectedSatiety == 2, + onTap: () { + context.read().add(ChangeSatiety(2)); + }, + ), + ScaleElement( + color: Colors.lime, + isSelected: state.selectedSatiety == 3, + onTap: () { + context.read().add(ChangeSatiety(3)); + }, + ), + ScaleElement( + color: Colors.lightGreen, + isSelected: state.selectedSatiety == 4, + onTap: () { + context.read().add(ChangeSatiety(4)); + }, + ), + ScaleElement( + color: Colors.green, + isSelected: state.selectedSatiety == 5, + onTap: () { + context.read().add(ChangeSatiety(5)); + }, + ), + Text("😊"), + // Остальные элементы шкалы + ], + ); + } else { + return Container(); // Возвращаем пустой контейнер, если состояние не является DiaryEditLoadedState + } + }, + ) ], ), )); @@ -387,7 +395,7 @@ class DiaryEditScreen extends StatelessWidget { ); } - Widget _buildHeaderColumn(BuildContext context) { + Widget _buildNutritionChart(BuildContext context) { return Container( margin: EdgeInsets.symmetric(horizontal: 16.h), padding: EdgeInsets.symmetric( @@ -797,8 +805,8 @@ class DiaryEditScreen extends StatelessWidget { child: Column(children: [ GestureDetector( onTap: () { - /*BlocProvider.of(context) - .add(ToggleWakeupExpandedEvent());*/ + BlocProvider.of(context) + .add(ToggleMoodExpandedEvent()); }, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,