From 82eca66ae4879fd4e57fd6b6c4f399c4fa2796e9 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Mon, 12 Feb 2024 15:02:43 +0300 Subject: [PATCH 01/32] feat(diary) Improved layouts and TimePicker --- .../bloc/diary_edit_bloc.dart | 12 +- .../bloc/diary_edit_state.dart | 14 ++- .../diary_edit_screen/diary_edit_screen.dart | 108 ++++++++---------- lib/widgets/custom_expandable_list_card.dart | 99 ++++++++++++++++ 4 files changed, 167 insertions(+), 66 deletions(-) create mode 100644 lib/widgets/custom_expandable_list_card.dart 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 7254d633..a4ad140c 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 @@ -39,11 +39,17 @@ class DiaryEditBloc extends Bloc { // Если текущее состояние уже загружено, обновляем его var currentState = state as DiaryEditLoadedState; // Обновляем значения контроллеров только если они уже были созданы - - emit((currentState).copyWith()); + print(currentState.wakeupController); + emit((currentState).copyWith( + wakeupController: currentState.wakeupController, + retireController: currentState.retireController, + )); } else { // Если текущее состояние - начальное, создаем новое загруженное состояние - emit(DiaryEditLoadedState()); + emit(DiaryEditLoadedState( + wakeupController: TimeOfDay.now(), + retireController: TimeOfDay.now(), + )); } } else { // Один или несколько ключевых полей отсутствуют, обрабатываем ошибку diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart index 7b9da4ab..9c82ff9a 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart @@ -18,19 +18,25 @@ class DiaryEditInitialState extends DiaryEditState { /// Represents the state of DiaryEdit in the application. class DiaryEditLoadedState extends DiaryEditState { - DiaryEditLoadedState({this.diaryEditModelObj}) + DiaryEditLoadedState( + {this.diaryEditModelObj, this.wakeupController, this.retireController}) : super(diaryEditModelObj: null); DiaryEditModel? diaryEditModelObj; + TimeOfDay? wakeupController; + TimeOfDay? retireController; @override - List get props => [ - diaryEditModelObj, - ]; + List get props => + [diaryEditModelObj, wakeupController, retireController]; DiaryEditLoadedState copyWith({ DiaryEditModel? diaryEditModelObj, + TimeOfDay? wakeupController, + TimeOfDay? retireController, }) { return DiaryEditLoadedState( diaryEditModelObj: diaryEditModelObj ?? this.diaryEditModelObj, + wakeupController: wakeupController ?? this.wakeupController, + retireController: retireController ?? this.retireController, ); } } 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 7d19300e..34ac3cc4 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -6,6 +6,7 @@ import 'package:eatvio_app/widgets/custom_text_form_field.dart'; import 'package:eatvio_app/widgets/custom_edit_drop_down.dart'; import 'package:eatvio_app/widgets/custom_outlined_button.dart'; import 'package:eatvio_app/widgets/custom_icon_button.dart'; +import 'package:eatvio_app/widgets/custom_expandable_list_card.dart'; // ignore: must_be_immutable class DiaryEditScreen extends StatelessWidget { @@ -26,20 +27,19 @@ class DiaryEditScreen extends StatelessWidget { "Item Three", ]; - TextEditingController enterProductNameController = TextEditingController(); - - TextEditingController quantityController = TextEditingController(); - List dropdownItemList2 = [ "Item One", "Item Two", "Item Three", ]; - List dropdownItemList3 = [ - "Item One", - "Item Two", - "Item Three", + List moodList = [ + "Ужасное", + "Плохое", + "Удовлетворительное", + "Нормальное", + "Хорошее", + "Прекрасное", ]; static Widget builder(BuildContext context) { @@ -91,43 +91,11 @@ class DiaryEditScreen extends StatelessWidget { children: [ _buildHeaderRow(context), SizedBox(height: 30.v), - Padding( - padding: EdgeInsets.symmetric(horizontal: 16.h), - child: CustomDropDown( - icon: Container( - margin: - EdgeInsets.fromLTRB(30.h, 24.v, 20.h, 22.v), - child: CustomImageView( - imagePath: ImageConstant.imgArrowLeft, - height: 10.v, - width: 18.h, - ), - ), - hintText: "Подъём \\ уход ко сну", - items: dropdownItemList, - onChanged: (value) {}, - ), - ), + _buildWakupRetire(), SizedBox(height: 30.v), _buildImageStack(context), SizedBox(height: 20.v), - Padding( - padding: EdgeInsets.symmetric(horizontal: 16.h), - child: CustomDropDown( - icon: Container( - margin: - EdgeInsets.fromLTRB(30.h, 30.v, 20.h, 30.v), - child: CustomImageView( - imagePath: ImageConstant.imgArrowLeft, - height: 10.v, - width: 18.h, - ), - ), - hintText: "Ваше настроение после приема пищи", - items: dropdownItemList3, - onChanged: (value) {}, - ), - ), + _buildMood(moodList), SizedBox(height: 30.v), _buildHeaderColumn(context), SizedBox(height: 30.v), @@ -148,7 +116,7 @@ class DiaryEditScreen extends StatelessWidget { /// Section Widget Widget _buildHeaderRow(BuildContext context) { return Container( - margin: EdgeInsets.symmetric(horizontal: 16.h), + margin: EdgeInsets.symmetric(horizontal: 16.h, vertical: 16.h), padding: EdgeInsets.symmetric( horizontal: 24.h, vertical: 12.v, @@ -160,14 +128,10 @@ class DiaryEditScreen extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ CustomImageView( - imagePath: ImageConstant.imgArrowLeft, - height: 2.v, - width: 20.h, - margin: EdgeInsets.only( - top: 19.v, - bottom: 17.v, - ), - ), + imagePath: ImageConstant.imgArrowLeft, + onTap: () { + NavigatorService.goBack(); + }), Padding( padding: EdgeInsets.only(top: 1.v), child: Column( @@ -193,19 +157,20 @@ class DiaryEditScreen extends StatelessWidget { } /// Section Widget - Widget _buildHeaderButton1(BuildContext context) { - return CustomOutlinedButton( - width: 73.h, - text: "14:52", + Widget _buildMealTime(BuildContext context) { + return Padding( + padding: EdgeInsets.symmetric(horizontal: 10.h), + child: CustomTextFormField( + hintText: "14:52", + ), ); } /// Section Widget Widget _buildEnterProductName(BuildContext context) { return Padding( - padding: EdgeInsets.symmetric(horizontal: 10.h), + padding: EdgeInsets.symmetric(horizontal: 8.h), child: CustomTextFormField( - controller: enterProductNameController, hintText: "Введите названия продукта", ), ); @@ -215,7 +180,6 @@ class DiaryEditScreen extends StatelessWidget { Widget _buildQuantity(BuildContext context) { return CustomTextFormField( width: 146.h, - controller: quantityController, hintText: "Кол-во", textInputAction: TextInputAction.done, ); @@ -285,7 +249,7 @@ class DiaryEditScreen extends StatelessWidget { style: CustomTextStyles.bodyMediumBlack900, ), ), - _buildHeaderButton1(context), + _buildMealTime(context), ], ), ), @@ -815,3 +779,29 @@ class DiaryEditScreen extends StatelessWidget { ); } } + +Widget _buildWakupRetire() { + return Padding( + padding: EdgeInsets.symmetric(horizontal: 16.h), + child: ExpandableList(r'Подъем \ уход ко сну'), + ); +} + +Widget _buildMood(List moodList) { + return Padding( + padding: EdgeInsets.symmetric(horizontal: 16.h), + child: CustomDropDown( + icon: Container( + margin: EdgeInsets.fromLTRB(30.h, 30.v, 20.h, 30.v), + child: CustomImageView( + imagePath: ImageConstant.imgArrowLeft, + height: 10.v, + width: 18.h, + ), + ), + hintText: "Ваше настроение после приема пищи", + items: moodList, + onChanged: (value) {}, + ), + ); +} diff --git a/lib/widgets/custom_expandable_list_card.dart b/lib/widgets/custom_expandable_list_card.dart new file mode 100644 index 00000000..4ac3be56 --- /dev/null +++ b/lib/widgets/custom_expandable_list_card.dart @@ -0,0 +1,99 @@ +import 'package:eatvio_app/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart'; +import 'package:flutter/material.dart'; +import 'package:eatvio_app/core/app_export.dart'; + +class ExpandableList extends StatefulWidget { + final String title; + + ExpandableList(this.title); + @override + _ExpandableListState createState() => _ExpandableListState(); +} + +class _ExpandableListState extends State { + bool isExpanded = false; + @override + Widget build(BuildContext context) { + return BlocBuilder( + builder: (context, state) { + return Container( + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, + ), + decoration: AppDecoration.outlinePrimary.copyWith( + borderRadius: BorderRadiusStyle.roundedBorder12, + ), + child: Column( + children: [ + GestureDetector( + onTap: () { + setState(() { + isExpanded = !isExpanded; + }); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + widget.title, + style: CustomTextStyles.bodyMediumBlack900, + ), + Icon(isExpanded + ? Icons.arrow_drop_up + : Icons.arrow_drop_down), + ], + ), + ), + if (isExpanded) + Padding( + padding: const EdgeInsets.only(left: 16.0), + child: Column( + children: [ + GestureDetector( + onTap: () => _selectTime(context), + child: AbsorbPointer( + child: TextFormField( + decoration: InputDecoration( + labelText: 'Во сколько вы просунились?', + suffixIcon: Icon(Icons.access_time), + ), + initialValue: + '${TimeOfDay.now().hour}:${TimeOfDay.now().minute.toString().padLeft(2, '0')}', + ), + ), + ), + GestureDetector( + onTap: () => _selectTime(context), + child: AbsorbPointer( + child: TextFormField( + decoration: InputDecoration( + labelText: 'о сколько вы легли спать?', + suffixIcon: Icon(Icons.access_time), + ), + initialValue: + '${TimeOfDay.now().hour}:${TimeOfDay.now().minute.toString().padLeft(2, '0')}', + ), + ), + ) + ], + ), + ), + ], + )); + }); + } + + Future _selectTime( + BuildContext context, DiaryEditLoadedState state) async { + final TimeOfDay? pickedTime = await showTimePicker( + context: context, + initialTime: state.wakeupController ?? TimeOfDay.now(), + ); + if (pickedTime != null && pickedTime != state.wakeupController) { + setState(() { + state.wakeupController = pickedTime; + }); + } + } +} From 7da4cb80143ddb9d579650ec0feb3e852f3d2ecc Mon Sep 17 00:00:00 2001 From: maxxkim Date: Tue, 13 Feb 2024 18:24:35 +0300 Subject: [PATCH 02/32] refactor(diary) Added more layouts and constrollers --- .../auth/auth_screen/auth_screen.dart | 8 ++ .../bloc/diary_edit_bloc.dart | 15 ++- .../bloc/diary_edit_event.dart | 2 + .../bloc/diary_edit_state.dart | 19 +++- .../diary_edit_screen/diary_edit_screen.dart | 79 ++++++++++++++- lib/widgets/custom_expandable_list_card.dart | 99 ------------------- 6 files changed, 112 insertions(+), 110 deletions(-) delete mode 100644 lib/widgets/custom_expandable_list_card.dart diff --git a/lib/presentation/auth/auth_screen/auth_screen.dart b/lib/presentation/auth/auth_screen/auth_screen.dart index 19bcac26..c037c382 100644 --- a/lib/presentation/auth/auth_screen/auth_screen.dart +++ b/lib/presentation/auth/auth_screen/auth_screen.dart @@ -68,6 +68,14 @@ class AuthScreen extends StatelessWidget { Navigator.pushNamed( context, AppRoutes.languageSelectScreen); }), + NextStepButton( + text: "Тест дневника".toUpperCase(), + margin: + EdgeInsets.only(left: 16.h, right: 16.h, bottom: 50.v), + buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + onPressed: () { + Navigator.pushNamed(context, AppRoutes.diaryEdit); + }), BlocBuilder(builder: (context, state) { return NextStepButton( text: "authentificate".tr.toUpperCase(), 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 a4ad140c..4425e5fc 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 @@ -21,8 +21,10 @@ class DiaryEditBloc extends Bloc { Emitter emit, ) async { try { - final box = await Hive.openBox('token'); - final token = box.get('token'); + /*final box = await Hive.openBox('token'); + final token = box.get('token');*/ + final token = + "1|laravel_sanctum_JBjDvwoEpmFc7CmzBaktFtZPGfSpXcEVA5YgBQ380d322d92"; final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/index'), headers: { @@ -41,12 +43,16 @@ class DiaryEditBloc extends Bloc { // Обновляем значения контроллеров только если они уже были созданы print(currentState.wakeupController); emit((currentState).copyWith( + wakeupExpanded: currentState.wakeupExpanded, + retireExpanded: currentState.retireExpanded, wakeupController: currentState.wakeupController, retireController: currentState.retireController, )); } else { // Если текущее состояние - начальное, создаем новое загруженное состояние emit(DiaryEditLoadedState( + wakeupExpanded: true, + retireExpanded: false, wakeupController: TimeOfDay.now(), retireController: TimeOfDay.now(), )); @@ -65,4 +71,9 @@ class DiaryEditBloc extends Bloc { emit(DiaryEditErrorState('Ошибка при получении данных профиля: $e')); } } + + /*_expandWakeup( + ToggleWakeupExpandedEvent event, Emitter emit) { + emit(state.copyWith(wakeupExpanded: !state.wakeupExpanded)); + }*/ } 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 ea52a649..6997cf72 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 @@ -14,3 +14,5 @@ class DiaryEditInitialEvent extends DiaryEditEvent { @override List get props => []; } + +class ToggleWakeupExpandedEvent extends DiaryEditEvent {} diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart index 9c82ff9a..af812b00 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart @@ -19,12 +19,18 @@ class DiaryEditInitialState extends DiaryEditState { /// Represents the state of DiaryEdit in the application. class DiaryEditLoadedState extends DiaryEditState { DiaryEditLoadedState( - {this.diaryEditModelObj, this.wakeupController, this.retireController}) + {this.diaryEditModelObj, + this.wakeupController, + this.retireController, + required this.wakeupExpanded, + required this.retireExpanded}) : super(diaryEditModelObj: null); DiaryEditModel? diaryEditModelObj; TimeOfDay? wakeupController; TimeOfDay? retireController; + bool wakeupExpanded; + bool retireExpanded; @override List get props => [diaryEditModelObj, wakeupController, retireController]; @@ -32,12 +38,15 @@ class DiaryEditLoadedState extends DiaryEditState { DiaryEditModel? diaryEditModelObj, TimeOfDay? wakeupController, TimeOfDay? retireController, + required bool wakeupExpanded, + required bool retireExpanded, }) { return DiaryEditLoadedState( - diaryEditModelObj: diaryEditModelObj ?? this.diaryEditModelObj, - wakeupController: wakeupController ?? this.wakeupController, - retireController: retireController ?? this.retireController, - ); + diaryEditModelObj: diaryEditModelObj ?? this.diaryEditModelObj, + wakeupController: wakeupController ?? this.wakeupController, + retireController: retireController ?? this.retireController, + wakeupExpanded: wakeupExpanded, + retireExpanded: retireExpanded); } } 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 34ac3cc4..aaa3d707 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -6,7 +6,6 @@ import 'package:eatvio_app/widgets/custom_text_form_field.dart'; import 'package:eatvio_app/widgets/custom_edit_drop_down.dart'; import 'package:eatvio_app/widgets/custom_outlined_button.dart'; import 'package:eatvio_app/widgets/custom_icon_button.dart'; -import 'package:eatvio_app/widgets/custom_expandable_list_card.dart'; // ignore: must_be_immutable class DiaryEditScreen extends StatelessWidget { @@ -91,7 +90,7 @@ class DiaryEditScreen extends StatelessWidget { children: [ _buildHeaderRow(context), SizedBox(height: 30.v), - _buildWakupRetire(), + _buildWakupRetire(context, state), SizedBox(height: 30.v), _buildImageStack(context), SizedBox(height: 20.v), @@ -780,10 +779,71 @@ class DiaryEditScreen extends StatelessWidget { } } -Widget _buildWakupRetire() { +Widget _buildWakupRetire(BuildContext context, DiaryEditLoadedState state) { return Padding( padding: EdgeInsets.symmetric(horizontal: 16.h), - child: ExpandableList(r'Подъем \ уход ко сну'), + child: Container( + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, + ), + decoration: AppDecoration.outlinePrimary.copyWith( + borderRadius: BorderRadiusStyle.roundedBorder12, + ), + child: Column( + children: [ + GestureDetector( + onTap: () { + BlocProvider.of(context) + .add(ToggleWakeupExpandedEvent()); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + r"Подъем \ отход ко сну", + style: CustomTextStyles.bodyMediumBlack900, + ), + Icon(state.wakeupExpanded + ? Icons.arrow_drop_up + : Icons.arrow_drop_down), + ], + ), + ), + if (state.wakeupExpanded) + Padding( + padding: const EdgeInsets.only(left: 16.0), + child: Column( + children: [ + GestureDetector( + onTap: () => _selectTime(context, state), + child: AbsorbPointer( + child: TextFormField( + decoration: InputDecoration( + labelText: 'Во сколько вы просунились?', + suffixIcon: Icon(Icons.access_time), + ), + initialValue: state.wakeupController.toString(), + ), + ), + ), + GestureDetector( + onTap: () => _selectTime(context, state), + child: AbsorbPointer( + child: TextFormField( + decoration: InputDecoration( + labelText: ' сколько вы легли спать?', + suffixIcon: Icon(Icons.access_time), + ), + initialValue: state.retireController.toString(), + ), + ), + ) + ], + ), + ), + ], + )), ); } @@ -805,3 +865,14 @@ Widget _buildMood(List moodList) { ), ); } + +Future _selectTime( + BuildContext context, DiaryEditLoadedState state) async { + final TimeOfDay? pickedTime = await showTimePicker( + context: context, + initialTime: state.wakeupController ?? TimeOfDay.now(), + ); + if (pickedTime != null && pickedTime != state.wakeupController) { + state.wakeupController = pickedTime; + } +} diff --git a/lib/widgets/custom_expandable_list_card.dart b/lib/widgets/custom_expandable_list_card.dart deleted file mode 100644 index 4ac3be56..00000000 --- a/lib/widgets/custom_expandable_list_card.dart +++ /dev/null @@ -1,99 +0,0 @@ -import 'package:eatvio_app/presentation/diary/diary_edit_screen/bloc/diary_edit_bloc.dart'; -import 'package:flutter/material.dart'; -import 'package:eatvio_app/core/app_export.dart'; - -class ExpandableList extends StatefulWidget { - final String title; - - ExpandableList(this.title); - @override - _ExpandableListState createState() => _ExpandableListState(); -} - -class _ExpandableListState extends State { - bool isExpanded = false; - @override - Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - return Container( - padding: EdgeInsets.symmetric( - horizontal: 24.h, - vertical: 12.v, - ), - decoration: AppDecoration.outlinePrimary.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder12, - ), - child: Column( - children: [ - GestureDetector( - onTap: () { - setState(() { - isExpanded = !isExpanded; - }); - }, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - widget.title, - style: CustomTextStyles.bodyMediumBlack900, - ), - Icon(isExpanded - ? Icons.arrow_drop_up - : Icons.arrow_drop_down), - ], - ), - ), - if (isExpanded) - Padding( - padding: const EdgeInsets.only(left: 16.0), - child: Column( - children: [ - GestureDetector( - onTap: () => _selectTime(context), - child: AbsorbPointer( - child: TextFormField( - decoration: InputDecoration( - labelText: 'Во сколько вы просунились?', - suffixIcon: Icon(Icons.access_time), - ), - initialValue: - '${TimeOfDay.now().hour}:${TimeOfDay.now().minute.toString().padLeft(2, '0')}', - ), - ), - ), - GestureDetector( - onTap: () => _selectTime(context), - child: AbsorbPointer( - child: TextFormField( - decoration: InputDecoration( - labelText: 'о сколько вы легли спать?', - suffixIcon: Icon(Icons.access_time), - ), - initialValue: - '${TimeOfDay.now().hour}:${TimeOfDay.now().minute.toString().padLeft(2, '0')}', - ), - ), - ) - ], - ), - ), - ], - )); - }); - } - - Future _selectTime( - BuildContext context, DiaryEditLoadedState state) async { - final TimeOfDay? pickedTime = await showTimePicker( - context: context, - initialTime: state.wakeupController ?? TimeOfDay.now(), - ); - if (pickedTime != null && pickedTime != state.wakeupController) { - setState(() { - state.wakeupController = pickedTime; - }); - } - } -} From 5118697a02c8c6a81e2dbb3c074fb97c7ea20111 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 14 Feb 2024 10:02:48 +0300 Subject: [PATCH 03/32] feat(diary) Mood list layouts --- .../bloc/diary_edit_event.dart | 2 +- .../diary_edit_screen/diary_edit_screen.dart | 59 +++++++++++++------ 2 files changed, 41 insertions(+), 20 deletions(-) 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 6997cf72..183f4500 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,4 +15,4 @@ class DiaryEditInitialEvent extends DiaryEditEvent { List get props => []; } -class ToggleWakeupExpandedEvent extends DiaryEditEvent {} +//class ToggleWakeupExpandedEvent extends DiaryEditEvent {} 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 aaa3d707..c345b3fa 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -94,7 +94,7 @@ class DiaryEditScreen extends StatelessWidget { SizedBox(height: 30.v), _buildImageStack(context), SizedBox(height: 20.v), - _buildMood(moodList), + _buildMood(moodList, context, state), SizedBox(height: 30.v), _buildHeaderColumn(context), SizedBox(height: 30.v), @@ -794,8 +794,8 @@ Widget _buildWakupRetire(BuildContext context, DiaryEditLoadedState state) { children: [ GestureDetector( onTap: () { - BlocProvider.of(context) - .add(ToggleWakeupExpandedEvent()); + /*BlocProvider.of(context) + .add(ToggleWakeupExpandedEvent());*/ }, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -832,7 +832,7 @@ Widget _buildWakupRetire(BuildContext context, DiaryEditLoadedState state) { child: AbsorbPointer( child: TextFormField( decoration: InputDecoration( - labelText: ' сколько вы легли спать?', + labelText: 'Во сколько вы легли спать?', suffixIcon: Icon(Icons.access_time), ), initialValue: state.retireController.toString(), @@ -847,23 +847,44 @@ Widget _buildWakupRetire(BuildContext context, DiaryEditLoadedState state) { ); } -Widget _buildMood(List moodList) { +Widget _buildMood( + List moodList, BuildContext context, DiaryEditLoadedState state) { return Padding( - padding: EdgeInsets.symmetric(horizontal: 16.h), - child: CustomDropDown( - icon: Container( - margin: EdgeInsets.fromLTRB(30.h, 30.v, 20.h, 30.v), - child: CustomImageView( - imagePath: ImageConstant.imgArrowLeft, - height: 10.v, - width: 18.h, + padding: EdgeInsets.symmetric(horizontal: 16.h), + child: Column(children: [ + GestureDetector( + onTap: () { + /*BlocProvider.of(context) + .add(ToggleWakeupExpandedEvent());*/ + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Ваше настроение после приема пищи", + style: CustomTextStyles.bodyMediumBlack900, + ), + Icon(state.wakeupExpanded + ? Icons.arrow_drop_up + : Icons.arrow_drop_down), + ], + ), ), - ), - hintText: "Ваше настроение после приема пищи", - items: moodList, - onChanged: (value) {}, - ), - ); + if (state.wakeupExpanded) + CustomDropDown( + icon: Container( + margin: EdgeInsets.fromLTRB(30.h, 30.v, 20.h, 30.v), + child: CustomImageView( + imagePath: ImageConstant.imgArrowLeft, + height: 10.v, + width: 18.h, + ), + ), + hintText: "Ваше настроение после приема пищи", + items: moodList, + onChanged: (value) {}, + ), + ])); } Future _selectTime( From f25bbfecbfece53610400068bb9606ece7ff55a6 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 14 Feb 2024 10:59:15 +0300 Subject: [PATCH 04/32] feat(diary) Comment layouts and controllers --- .../bloc/diary_edit_bloc.dart | 50 +-- .../bloc/diary_edit_state.dart | 12 +- .../diary_edit_screen/diary_edit_screen.dart | 293 ++++++++---------- 3 files changed, 165 insertions(+), 190 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 4425e5fc..98c218dd 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 @@ -20,7 +20,7 @@ class DiaryEditBloc extends Bloc { DiaryEditInitialEvent event, Emitter emit, ) async { - try { + /*try { /*final box = await Hive.openBox('token'); final token = box.get('token');*/ final token = @@ -36,28 +36,30 @@ class DiaryEditBloc extends Bloc { final data = jsonDecode(response.body); // Проверка наличия ключевых полей в JSON if (data is Map && data.containsKey('id')) { - // Все ключевые поля присутствуют, продолжаем обработку - if (state is DiaryEditLoadedState) { - // Если текущее состояние уже загружено, обновляем его - var currentState = state as DiaryEditLoadedState; - // Обновляем значения контроллеров только если они уже были созданы - print(currentState.wakeupController); - emit((currentState).copyWith( - wakeupExpanded: currentState.wakeupExpanded, - retireExpanded: currentState.retireExpanded, - wakeupController: currentState.wakeupController, - retireController: currentState.retireController, - )); - } else { - // Если текущее состояние - начальное, создаем новое загруженное состояние - emit(DiaryEditLoadedState( - wakeupExpanded: true, - retireExpanded: false, - wakeupController: TimeOfDay.now(), - retireController: TimeOfDay.now(), - )); - } - } else { + // Все ключевые поля присутствуют, продолжаем обработку*/ + if (state is DiaryEditLoadedState) { + // Если текущее состояние уже загружено, обновляем его + var currentState = state as DiaryEditLoadedState; + // Обновляем значения контроллеров только если они уже были созданы + print(currentState.wakeupController); + emit((currentState).copyWith( + wakeupExpanded: currentState.wakeupExpanded, + moodExpanded: currentState.moodExpanded, + wakeupController: currentState.wakeupController, + retireController: currentState.retireController, + commentController: currentState.commentController, + )); + } else { + // Если текущее состояние - начальное, создаем новое загруженное состояние + emit(DiaryEditLoadedState( + wakeupExpanded: true, + moodExpanded: true, + wakeupController: TimeOfDay.now(), + retireController: TimeOfDay.now(), + commentController: TextEditingController(), + )); + } + /*} else { // Один или несколько ключевых полей отсутствуют, обрабатываем ошибку emit( DiaryEditErrorState('Некоторые необходимые данные отсутствуют.')); @@ -69,7 +71,7 @@ class DiaryEditBloc extends Bloc { } catch (e) { // Ошибка при декодировании JSON или другая ошибка выполнения emit(DiaryEditErrorState('Ошибка при получении данных профиля: $e')); - } + }*/ } /*_expandWakeup( diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart index af812b00..28cdd066 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart @@ -22,15 +22,17 @@ class DiaryEditLoadedState extends DiaryEditState { {this.diaryEditModelObj, this.wakeupController, this.retireController, + this.commentController, required this.wakeupExpanded, - required this.retireExpanded}) + required this.moodExpanded}) : super(diaryEditModelObj: null); DiaryEditModel? diaryEditModelObj; TimeOfDay? wakeupController; TimeOfDay? retireController; + TextEditingController? commentController; bool wakeupExpanded; - bool retireExpanded; + bool moodExpanded; @override List get props => [diaryEditModelObj, wakeupController, retireController]; @@ -38,15 +40,17 @@ class DiaryEditLoadedState extends DiaryEditState { DiaryEditModel? diaryEditModelObj, TimeOfDay? wakeupController, TimeOfDay? retireController, + TextEditingController? commentController, required bool wakeupExpanded, - required bool retireExpanded, + required bool moodExpanded, }) { return DiaryEditLoadedState( diaryEditModelObj: diaryEditModelObj ?? this.diaryEditModelObj, wakeupController: wakeupController ?? this.wakeupController, retireController: retireController ?? this.retireController, + commentController: commentController ?? this.commentController, wakeupExpanded: wakeupExpanded, - retireExpanded: retireExpanded); + moodExpanded: moodExpanded); } } 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 c345b3fa..b378e32c 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -98,7 +98,7 @@ class DiaryEditScreen extends StatelessWidget { SizedBox(height: 30.v), _buildHeaderColumn(context), SizedBox(height: 30.v), - _buildHeaderStack(context), + _buildComment(context), ], ), ), @@ -681,87 +681,116 @@ class DiaryEditScreen extends StatelessWidget { } /// Section Widget - Widget _buildHeaderColumn1(BuildContext context) { - return Align( - alignment: Alignment.center, - child: Container( - margin: EdgeInsets.symmetric(horizontal: 15.h), - padding: EdgeInsets.symmetric( - horizontal: 50.h, - vertical: 28.v, - ), - decoration: AppDecoration.outlinePrimary.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder12, - ), - child: SizedBox( - width: 240.h, - child: Text( - "Дополнительная информация для консультанта", - maxLines: 2, - overflow: TextOverflow.ellipsis, - textAlign: TextAlign.center, - style: CustomTextStyles.bodyMediumBlack900, + Widget _buildComment(BuildContext context, DiaryEditLoadedState state) { + return Padding( + padding: EdgeInsets.symmetric(horizontal: 16.h), + child: Container( + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, ), - ), - ), - ); + decoration: AppDecoration.outlinePrimary.copyWith( + borderRadius: BorderRadiusStyle.roundedBorder12, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "Дополнительная информация для консультанта", + style: theme.textTheme.titleMedium, + textAlign: TextAlign.center, + ), + Align( + alignment: Alignment.bottomCenter, + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox(height: 20.v), + Container( + width: 320.h, + child: CustomTextFormField( + autofocus: false, + hintText: "Введите информацию для консультанта", + maxLines: 7, + borderDecoration: InputBorder.none, + controller: state.commentController, + ), + ), + ], + ), + ), + ], + ), + )); } - /// Section Widget - Widget _buildHeaderStack(BuildContext context) { - return SizedBox( - height: 235.v, - width: 374.h, - child: Stack( - alignment: Alignment.bottomCenter, - children: [ - _buildHeaderColumn1(context), - Align( - alignment: Alignment.bottomCenter, - child: Padding( - padding: EdgeInsets.only(bottom: 103.v), - child: SizedBox( - width: 374.h, - child: Divider(), - ), - ), + Widget _buildWakupRetire(BuildContext context, DiaryEditLoadedState state) { + return Padding( + padding: EdgeInsets.symmetric(horizontal: 16.h), + child: Container( + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, ), - Align( - alignment: Alignment.bottomCenter, - child: Container( - margin: EdgeInsets.only( - left: 35.h, - right: 35.h, - bottom: 20.v, - ), - padding: EdgeInsets.symmetric( - horizontal: 14.h, - vertical: 9.v, - ), - decoration: AppDecoration.outlineBlueGray.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder5, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - SizedBox(height: 63.v), - Container( - width: 245.h, - margin: EdgeInsets.only(right: 27.h), - child: Text( - "Введите дополнитльеную информацию для консультанта", - maxLines: 2, - overflow: TextOverflow.ellipsis, - style: theme.textTheme.bodyLarge, + decoration: AppDecoration.outlinePrimary.copyWith( + borderRadius: BorderRadiusStyle.roundedBorder12, + ), + child: Column( + children: [ + GestureDetector( + onTap: () { + /*BlocProvider.of(context) + .add(ToggleWakeupExpandedEvent());*/ + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + r"Подъем \ отход ко сну", + style: CustomTextStyles.bodyMediumBlack900, ), - ), - ], + Icon(state.wakeupExpanded + ? Icons.arrow_drop_up + : Icons.arrow_drop_down), + ], + ), ), - ), - ), - ], - ), + if (state.wakeupExpanded) + Padding( + padding: const EdgeInsets.only(left: 16.0), + child: Column( + children: [ + GestureDetector( + onTap: () => _selectTime(context, state), + child: AbsorbPointer( + child: TextFormField( + decoration: InputDecoration( + labelText: 'Во сколько вы просунились?', + suffixIcon: Icon(Icons.access_time), + ), + initialValue: state.wakeupController.toString(), + ), + ), + ), + GestureDetector( + onTap: () => _selectTime(context, state), + child: AbsorbPointer( + child: TextFormField( + decoration: InputDecoration( + labelText: 'Во сколько вы легли спать?', + suffixIcon: Icon(Icons.access_time), + ), + initialValue: state.retireController.toString(), + ), + ), + ) + ], + ), + ), + ], + )), ); } @@ -779,19 +808,19 @@ class DiaryEditScreen extends StatelessWidget { } } -Widget _buildWakupRetire(BuildContext context, DiaryEditLoadedState state) { +Widget _buildMood( + List moodList, BuildContext context, DiaryEditLoadedState state) { return Padding( - padding: EdgeInsets.symmetric(horizontal: 16.h), - child: Container( - padding: EdgeInsets.symmetric( - horizontal: 24.h, - vertical: 12.v, - ), - decoration: AppDecoration.outlinePrimary.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder12, - ), - child: Column( - children: [ + padding: EdgeInsets.symmetric(horizontal: 16.h), + child: Container( + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, + ), + decoration: AppDecoration.outlinePrimary.copyWith( + borderRadius: BorderRadiusStyle.roundedBorder12, + ), + child: Column(children: [ GestureDetector( onTap: () { /*BlocProvider.of(context) @@ -801,7 +830,7 @@ Widget _buildWakupRetire(BuildContext context, DiaryEditLoadedState state) { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - r"Подъем \ отход ко сну", + "Ваше настроение после приема пищи", style: CustomTextStyles.bodyMediumBlack900, ), Icon(state.wakeupExpanded @@ -810,81 +839,21 @@ Widget _buildWakupRetire(BuildContext context, DiaryEditLoadedState state) { ], ), ), - if (state.wakeupExpanded) - Padding( - padding: const EdgeInsets.only(left: 16.0), - child: Column( - children: [ - GestureDetector( - onTap: () => _selectTime(context, state), - child: AbsorbPointer( - child: TextFormField( - decoration: InputDecoration( - labelText: 'Во сколько вы просунились?', - suffixIcon: Icon(Icons.access_time), - ), - initialValue: state.wakeupController.toString(), - ), - ), - ), - GestureDetector( - onTap: () => _selectTime(context, state), - child: AbsorbPointer( - child: TextFormField( - decoration: InputDecoration( - labelText: 'Во сколько вы легли спать?', - suffixIcon: Icon(Icons.access_time), - ), - initialValue: state.retireController.toString(), - ), - ), - ) - ], + if (state.moodExpanded) + CustomDropDown( + icon: Container( + margin: EdgeInsets.fromLTRB(30.h, 30.v, 20.h, 30.v), + child: CustomImageView( + imagePath: ImageConstant.imgArrowLeft, + height: 10.v, + width: 18.h, + ), ), + hintText: "Ваше настроение после приема пищи", + items: moodList, + onChanged: (value) {}, ), - ], - )), - ); -} - -Widget _buildMood( - List moodList, BuildContext context, DiaryEditLoadedState state) { - return Padding( - padding: EdgeInsets.symmetric(horizontal: 16.h), - child: Column(children: [ - GestureDetector( - onTap: () { - /*BlocProvider.of(context) - .add(ToggleWakeupExpandedEvent());*/ - }, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Ваше настроение после приема пищи", - style: CustomTextStyles.bodyMediumBlack900, - ), - Icon(state.wakeupExpanded - ? Icons.arrow_drop_up - : Icons.arrow_drop_down), - ], - ), - ), - if (state.wakeupExpanded) - CustomDropDown( - icon: Container( - margin: EdgeInsets.fromLTRB(30.h, 30.v, 20.h, 30.v), - child: CustomImageView( - imagePath: ImageConstant.imgArrowLeft, - height: 10.v, - width: 18.h, - ), - ), - hintText: "Ваше настроение после приема пищи", - items: moodList, - onChanged: (value) {}, - ), - ])); + ]))); } Future _selectTime( From 2c2508840df24ffe0fc675ac1ba442cae17edc67 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 14 Feb 2024 13:06:01 +0300 Subject: [PATCH 05/32] feat(diary) New layoutsa and styles, build method edits --- .../diary_edit_screen/diary_edit_screen.dart | 697 +++++++++++------- lib/widgets/custom_edit_drop_down.dart | 5 +- 2 files changed, 434 insertions(+), 268 deletions(-) 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 b378e32c..fc254862 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -20,10 +20,13 @@ class DiaryEditScreen extends StatelessWidget { "Item Three", ]; - List dropdownItemList1 = [ - "Item One", - "Item Two", - "Item Three", + List mealList = [ + "Прием пищи 1", + "Прием пищи 2", + "Прием пищи 3", + "Прием пищи 4", + "Прием пищи 5", + "Прием пищи 6", ]; List dropdownItemList2 = [ @@ -77,7 +80,8 @@ class DiaryEditScreen extends StatelessWidget { mediaQueryData = MediaQuery.of(context); return SafeArea( child: Scaffold( - resizeToAvoidBottomInset: false, + backgroundColor: Color.fromARGB(255, 240, 242, 245), + resizeToAvoidBottomInset: true, body: SizedBox( width: double.maxFinite, child: Column( @@ -92,13 +96,14 @@ class DiaryEditScreen extends StatelessWidget { SizedBox(height: 30.v), _buildWakupRetire(context, state), SizedBox(height: 30.v), - _buildImageStack(context), + //_buildImageStack(context), + _buildMeal(context, state), SizedBox(height: 20.v), _buildMood(moodList, context, state), SizedBox(height: 30.v), _buildHeaderColumn(context), SizedBox(height: 30.v), - _buildComment(context), + _buildComment(context, state), ], ), ), @@ -120,8 +125,17 @@ class DiaryEditScreen extends StatelessWidget { horizontal: 24.h, vertical: 12.v, ), - decoration: AppDecoration.outlinePrimary.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder12, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(12), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + spreadRadius: 2, + blurRadius: 5, + offset: Offset(0, 3), + ), + ], ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -155,16 +169,6 @@ class DiaryEditScreen extends StatelessWidget { ); } - /// Section Widget - Widget _buildMealTime(BuildContext context) { - return Padding( - padding: EdgeInsets.symmetric(horizontal: 10.h), - child: CustomTextFormField( - hintText: "14:52", - ), - ); - } - /// Section Widget Widget _buildEnterProductName(BuildContext context) { return Padding( @@ -175,15 +179,6 @@ class DiaryEditScreen extends StatelessWidget { ); } - /// Section Widget - Widget _buildQuantity(BuildContext context) { - return CustomTextFormField( - width: 146.h, - hintText: "Кол-во", - textInputAction: TextInputAction.done, - ); - } - /// Section Widget Widget _buildAddProduct(BuildContext context) { return CustomOutlinedButton( @@ -211,245 +206,155 @@ class DiaryEditScreen extends StatelessWidget { ); } - /// Section Widget - Widget _buildImageStack(BuildContext context) { - return SizedBox( - height: 790.v, - width: 374.h, - child: Stack( - alignment: Alignment.bottomCenter, + _buildMeal(BuildContext context, DiaryEditLoadedState state) { + return Padding( + padding: EdgeInsets.symmetric(horizontal: 16.h), + child: Container( + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, + ), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(12), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + spreadRadius: 2, + blurRadius: 5, + offset: Offset(0, 3), + ), + ], + ), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: EdgeInsets.symmetric(horizontal: 10.h), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Время приема пищи", + style: CustomTextStyles.bodyMediumBlack900, + ), + Padding( + padding: EdgeInsets.symmetric(horizontal: 10.h), + child: ConstrainedBox( + constraints: BoxConstraints( + maxWidth: MediaQuery.of(context).size.width - 210, + ), + child: CustomTextFormField( + hintText: "14:52", + ), + ), + ), + ], + ), + ), + SizedBox(height: 20.v), + Padding( + padding: EdgeInsets.symmetric(horizontal: 10.h), + child: CustomDropDown( + hintText: "Прием пищи", + items: mealList, + contentPadding: EdgeInsets.symmetric( + horizontal: 15.h, + vertical: 9.v, + ), + onChanged: (value) {}, + ), + ), + SizedBox(height: 20.v), + _buildEnterProductName(context), + SizedBox(height: 20.v), + Padding( + padding: EdgeInsets.symmetric(horizontal: 10.h), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + CustomTextFormField( + width: 146.h, + hintText: "Кол-во", + textInputAction: TextInputAction.done, + ), + Padding( + padding: EdgeInsets.only(left: 10.h), + child: Text( + "порций", + style: CustomTextStyles.bodyMediumBlack900, + )), + ], + ), + ), + SizedBox(height: 30.v), + + _buildAddProduct(context), + SizedBox(height: 30.v), + //_buildAddPhoto(context), + SizedBox(height: 29.v), + Text( + "Ваша сытость после приёма пищи", + style: CustomTextStyles.bodyMediumBlack900, + ), + SizedBox(height: 15.v), + ], + ), + )); + } + + _buildProduct(BuildContext context) { + return Container( + margin: EdgeInsets.symmetric(horizontal: 10.h), + padding: EdgeInsets.symmetric( + horizontal: 8.h, + vertical: 6.v, + ), + decoration: AppDecoration.fillGray.copyWith( + borderRadius: BorderRadiusStyle.roundedBorder5, + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + mainAxisSize: MainAxisSize.min, children: [ - Align( - alignment: Alignment.center, - child: Container( - margin: EdgeInsets.symmetric(horizontal: 15.h), - padding: EdgeInsets.symmetric( - horizontal: 10.h, - vertical: 13.v, - ), - decoration: AppDecoration.outlinePrimary.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder12, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: EdgeInsets.symmetric(horizontal: 10.h), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Padding( - padding: EdgeInsets.only( - top: 11.v, - bottom: 7.v, - ), - child: Text( - "Время приема пищи", - style: CustomTextStyles.bodyMediumBlack900, - ), - ), - _buildMealTime(context), - ], - ), - ), - SizedBox(height: 20.v), - Padding( - padding: EdgeInsets.symmetric(horizontal: 10.h), - child: CustomDropDown( - hintText: "Прием пищи", - items: dropdownItemList1, - contentPadding: EdgeInsets.symmetric( - horizontal: 15.h, - vertical: 9.v, - ), - onChanged: (value) {}, - ), - ), - SizedBox(height: 20.v), - _buildEnterProductName(context), - SizedBox(height: 20.v), - Padding( - padding: EdgeInsets.symmetric(horizontal: 10.h), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - _buildQuantity(context), - Padding( - padding: EdgeInsets.only(left: 10.h), - child: CustomDropDown( - width: 146.h, - hintText: "Порция", - items: dropdownItemList2, - contentPadding: EdgeInsets.symmetric( - horizontal: 15.h, - vertical: 9.v, - ), - onChanged: (value) {}, - ), - ), - ], - ), - ), - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.symmetric(horizontal: 10.h), - padding: EdgeInsets.symmetric( - horizontal: 8.h, - vertical: 6.v, - ), - decoration: AppDecoration.fillGray.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder5, - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: EdgeInsets.only( - left: 7.h, - top: 5.v, - ), - child: Text( - "Сырный суп", - style: CustomTextStyles.titleMedium16, - ), - ), - Padding( - padding: EdgeInsets.only( - left: 20.h, - top: 3.v, - bottom: 3.v, - ), - child: Text( - "400мл", - style: CustomTextStyles.titleMedium16, - ), - ), - Spacer(), - CustomImageView( - imagePath: ImageConstant.imgSearch, - height: 24.adaptSize, - width: 24.adaptSize, - ), - CustomImageView( - imagePath: ImageConstant.imgClose, - height: 28.adaptSize, - width: 28.adaptSize, - margin: EdgeInsets.only(left: 10.h), - ), - ], - ), - ), - SizedBox(height: 30.v), - _buildAddProduct(context), - SizedBox(height: 249.v), - _buildAddPhoto(context), - SizedBox(height: 29.v), - Text( - "Ваша сытость после приёма пищи", - style: CustomTextStyles.bodyMediumBlack900, - ), - SizedBox(height: 15.v), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - CustomImageView( - imagePath: ImageConstant.imgEdit, - height: 30.adaptSize, - width: 30.adaptSize, - ), - CustomImageView( - height: 13.v, - width: 243.h, - margin: EdgeInsets.only( - left: 10.h, - top: 9.v, - bottom: 8.v, - ), - ), - CustomImageView( - height: 30.adaptSize, - width: 30.adaptSize, - margin: EdgeInsets.only(left: 10.h), - ), - ], - ), - SizedBox(height: 7.v), - ], - ), + Padding( + padding: EdgeInsets.only( + left: 7.h, + top: 5.v, + ), + child: Text( + "Сырный суп", + style: CustomTextStyles.titleMedium16, ), ), - Align( - alignment: Alignment.bottomCenter, - child: Padding( - padding: EdgeInsets.only(bottom: 342.v), - child: SizedBox( - width: 374.h, - child: Divider(), - ), + Padding( + padding: EdgeInsets.only( + left: 20.h, + top: 3.v, + bottom: 3.v, + ), + child: Text( + "400мл", + style: CustomTextStyles.titleMedium16, ), ), - Align( - alignment: Alignment.bottomCenter, - child: Container( - height: 203.v, - width: 303.h, - margin: EdgeInsets.only(bottom: 178.v), - child: Stack( - alignment: Alignment.topRight, - children: [ - CustomImageView( - height: 203.v, - width: 303.h, - radius: BorderRadius.circular( - 5.h, - ), - alignment: Alignment.center, - ), - Align( - alignment: Alignment.topRight, - child: Padding( - padding: EdgeInsets.only( - left: 265.h, - top: 10.v, - right: 10.h, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - CustomIconButton( - height: 18.adaptSize, - width: 18.adaptSize, - padding: EdgeInsets.all(4.h), - alignment: Alignment.centerRight, - child: CustomImageView( - imagePath: ImageConstant.imgCloseBlueGray900, - ), - ), - SizedBox(height: 60.v), - CustomIconButton( - height: 28.adaptSize, - width: 28.adaptSize, - padding: EdgeInsets.all(9.h), - decoration: IconButtonStyleHelper.fillBlueA, - child: CustomImageView( - imagePath: ImageConstant.imageNotFound, - ), - ), - ], - ), - ), - ), - ], - ), - ), + Spacer(), + CustomImageView( + imagePath: ImageConstant.imgSearch, + height: 24.adaptSize, + width: 24.adaptSize, + ), + CustomImageView( + imagePath: ImageConstant.imgClose, + height: 28.adaptSize, + width: 28.adaptSize, + margin: EdgeInsets.only(left: 10.h), ), ], ), ); } - /// Section Widget Widget _buildHeaderColumn(BuildContext context) { return Container( margin: EdgeInsets.symmetric(horizontal: 16.h), @@ -457,8 +362,17 @@ class DiaryEditScreen extends StatelessWidget { horizontal: 10.h, vertical: 16.v, ), - decoration: AppDecoration.outlinePrimary.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder12, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(12), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + spreadRadius: 2, + blurRadius: 5, + offset: Offset(0, 3), + ), + ], ), child: Column( mainAxisSize: MainAxisSize.min, @@ -659,7 +573,7 @@ class DiaryEditScreen extends StatelessWidget { ), Padding( padding: EdgeInsets.only( - left: 16.h, + left: 14.h, bottom: 11.v, ), child: Text( @@ -689,8 +603,17 @@ class DiaryEditScreen extends StatelessWidget { horizontal: 24.h, vertical: 12.v, ), - decoration: AppDecoration.outlinePrimary.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder12, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(12), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + spreadRadius: 2, + blurRadius: 5, + offset: Offset(0, 3), + ), + ], ), child: Column( mainAxisSize: MainAxisSize.min, @@ -734,8 +657,17 @@ class DiaryEditScreen extends StatelessWidget { horizontal: 24.h, vertical: 12.v, ), - decoration: AppDecoration.outlinePrimary.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder12, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(12), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + spreadRadius: 2, + blurRadius: 5, + offset: Offset(0, 3), + ), + ], ), child: Column( children: [ @@ -817,8 +749,17 @@ Widget _buildMood( horizontal: 24.h, vertical: 12.v, ), - decoration: AppDecoration.outlinePrimary.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder12, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(12), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + spreadRadius: 2, + blurRadius: 5, + offset: Offset(0, 3), + ), + ], ), child: Column(children: [ GestureDetector( @@ -866,3 +807,229 @@ Future _selectTime( state.wakeupController = pickedTime; } } + +/*Widget _buildImageStack(BuildContext context) { + return Container( + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, + ), + decoration: AppDecoration.outlinePrimary.copyWith( + borderRadius: BorderRadiusStyle.roundedBorder12, + ), + child: Stack( + alignment: Alignment.bottomCenter, + children: [ + Align( + alignment: Alignment.center, + child: Container( + margin: EdgeInsets.symmetric(horizontal: 10.h), + padding: EdgeInsets.symmetric( + horizontal: 10.h, + vertical: 13.v, + ), + decoration: AppDecoration.outlinePrimary.copyWith( + borderRadius: BorderRadiusStyle.roundedBorder12, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: EdgeInsets.symmetric(horizontal: 10.h), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Время приема пищи", + style: CustomTextStyles.bodyMediumBlack900, + ), + _buildMealTime(context), + ], + ), + ), + SizedBox(height: 20.v), + Padding( + padding: EdgeInsets.symmetric(horizontal: 10.h), + child: CustomDropDown( + hintText: "Прием пищи", + items: dropdownItemList1, + contentPadding: EdgeInsets.symmetric( + horizontal: 15.h, + vertical: 9.v, + ), + onChanged: (value) {}, + ), + ), + SizedBox(height: 20.v), + _buildEnterProductName(context), + SizedBox(height: 20.v), + Padding( + padding: EdgeInsets.symmetric(horizontal: 10.h), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + _buildQuantity(context), + Padding( + padding: EdgeInsets.only(left: 10.h), + child: CustomDropDown( + width: 146.h, + hintText: "Порция", + items: dropdownItemList2, + contentPadding: EdgeInsets.symmetric( + horizontal: 15.h, + vertical: 9.v, + ), + onChanged: (value) {}, + ), + ), + ], + ), + ), + SizedBox(height: 30.v), + Container( + margin: EdgeInsets.symmetric(horizontal: 10.h), + padding: EdgeInsets.symmetric( + horizontal: 8.h, + vertical: 6.v, + ), + decoration: AppDecoration.fillGray.copyWith( + borderRadius: BorderRadiusStyle.roundedBorder5, + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: EdgeInsets.only( + left: 7.h, + top: 5.v, + ), + child: Text( + "Сырный суп", + style: CustomTextStyles.titleMedium16, + ), + ), + Padding( + padding: EdgeInsets.only( + left: 20.h, + top: 3.v, + bottom: 3.v, + ), + child: Text( + "400мл", + style: CustomTextStyles.titleMedium16, + ), + ), + Spacer(), + CustomImageView( + imagePath: ImageConstant.imgSearch, + height: 24.adaptSize, + width: 24.adaptSize, + ), + CustomImageView( + imagePath: ImageConstant.imgClose, + height: 28.adaptSize, + width: 28.adaptSize, + margin: EdgeInsets.only(left: 10.h), + ), + ], + ), + ), + SizedBox(height: 30.v), + _buildAddProduct(context), + SizedBox(height: 249.v), + _buildAddPhoto(context), + SizedBox(height: 29.v), + Text( + "Ваша сытость после приёма пищи", + style: CustomTextStyles.bodyMediumBlack900, + ), + SizedBox(height: 15.v), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + CustomImageView( + imagePath: ImageConstant.imgEdit, + height: 30.adaptSize, + width: 30.adaptSize, + ), + CustomImageView( + height: 13.v, + width: 243.h, + margin: EdgeInsets.only( + left: 10.h, + top: 9.v, + bottom: 8.v, + ), + ), + CustomImageView( + height: 30.adaptSize, + width: 30.adaptSize, + margin: EdgeInsets.only(left: 10.h), + ), + ], + ), + SizedBox(height: 7.v), + ], + ), + ), + ), + Align( + alignment: Alignment.bottomCenter, + child: Container( + height: 203.v, + width: 303.h, + margin: EdgeInsets.only(bottom: 178.v), + child: Stack( + alignment: Alignment.topRight, + children: [ + CustomImageView( + height: 203.v, + width: 303.h, + radius: BorderRadius.circular( + 5.h, + ), + alignment: Alignment.center, + ), + Align( + alignment: Alignment.topRight, + child: Padding( + padding: EdgeInsets.only( + left: 265.h, + top: 10.v, + right: 10.h, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + CustomIconButton( + height: 18.adaptSize, + width: 18.adaptSize, + padding: EdgeInsets.all(4.h), + alignment: Alignment.centerRight, + child: CustomImageView( + imagePath: ImageConstant.imgCloseBlueGray900, + ), + ), + SizedBox(height: 60.v), + CustomIconButton( + height: 28.adaptSize, + width: 28.adaptSize, + padding: EdgeInsets.all(9.h), + decoration: IconButtonStyleHelper.fillBlueA, + child: CustomImageView( + imagePath: ImageConstant.imageNotFound, + ), + ), + ], + ), + ), + ), + ], + ), + ), + ), + ], + ), + ); + }*/ \ No newline at end of file diff --git a/lib/widgets/custom_edit_drop_down.dart b/lib/widgets/custom_edit_drop_down.dart index 12b98cf3..9e22b9ab 100644 --- a/lib/widgets/custom_edit_drop_down.dart +++ b/lib/widgets/custom_edit_drop_down.dart @@ -119,9 +119,8 @@ class CustomDropDown extends StatelessWidget { ), enabledBorder: borderDecoration ?? OutlineInputBorder( - borderRadius: BorderRadius.circular(8), - borderSide: BorderSide.none, - ), + borderRadius: BorderRadius.circular(8), + borderSide: BorderSide(color: Colors.grey, width: 1)), focusedBorder: borderDecoration ?? OutlineInputBorder( borderRadius: BorderRadius.circular(5), From 2fdf3979da64ec533bc13a4140a8edc0bef6cb02 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 14 Feb 2024 13:44:50 +0300 Subject: [PATCH 06/32] feat(diary) Finished static layouts --- .../diary_edit_screen/diary_edit_screen.dart | 195 +++++++++--------- lib/widgets/custom_edit_drop_down.dart | 12 +- lib/widgets/custom_edit_text_form_field.dart | 144 +++++++++++++ 3 files changed, 250 insertions(+), 101 deletions(-) create mode 100644 lib/widgets/custom_edit_text_form_field.dart 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 fc254862..d1b4c690 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -2,10 +2,9 @@ import 'bloc/diary_edit_bloc.dart'; import 'models/diary_edit_model.dart'; import 'package:flutter/material.dart'; import 'package:eatvio_app/core/app_export.dart'; -import 'package:eatvio_app/widgets/custom_text_form_field.dart'; +import 'package:eatvio_app/widgets/custom_edit_text_form_field.dart'; import 'package:eatvio_app/widgets/custom_edit_drop_down.dart'; import 'package:eatvio_app/widgets/custom_outlined_button.dart'; -import 'package:eatvio_app/widgets/custom_icon_button.dart'; // ignore: must_be_immutable class DiaryEditScreen extends StatelessWidget { @@ -14,12 +13,6 @@ class DiaryEditScreen extends StatelessWidget { key: key, ); - List dropdownItemList = [ - "Item One", - "Item Two", - "Item Three", - ]; - List mealList = [ "Прием пищи 1", "Прием пищи 2", @@ -29,10 +22,13 @@ class DiaryEditScreen extends StatelessWidget { "Прием пищи 6", ]; - List dropdownItemList2 = [ - "Item One", - "Item Two", - "Item Three", + List satietyList = [ + "Ужасное", + "Плохое", + "Удовлетворительное", + "Нормальное", + "Хорошее", + "Прекрасное", ]; List moodList = [ @@ -169,16 +165,6 @@ class DiaryEditScreen extends StatelessWidget { ); } - /// Section Widget - Widget _buildEnterProductName(BuildContext context) { - return Padding( - padding: EdgeInsets.symmetric(horizontal: 8.h), - child: CustomTextFormField( - hintText: "Введите названия продукта", - ), - ); - } - /// Section Widget Widget _buildAddProduct(BuildContext context) { return CustomOutlinedButton( @@ -242,7 +228,7 @@ class DiaryEditScreen extends StatelessWidget { padding: EdgeInsets.symmetric(horizontal: 10.h), child: ConstrainedBox( constraints: BoxConstraints( - maxWidth: MediaQuery.of(context).size.width - 210, + maxWidth: MediaQuery.of(context).size.width - 247, ), child: CustomTextFormField( hintText: "14:52", @@ -259,19 +245,24 @@ class DiaryEditScreen extends StatelessWidget { hintText: "Прием пищи", items: mealList, contentPadding: EdgeInsets.symmetric( - horizontal: 15.h, + horizontal: 10.h, vertical: 9.v, ), onChanged: (value) {}, ), ), SizedBox(height: 20.v), - _buildEnterProductName(context), + Padding( + padding: EdgeInsets.symmetric(horizontal: 10.h), + child: CustomTextFormField( + hintText: "Введите названия продукта", + ), + ), SizedBox(height: 20.v), Padding( padding: EdgeInsets.symmetric(horizontal: 10.h), child: Row( - mainAxisAlignment: MainAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ CustomTextFormField( width: 146.h, @@ -279,7 +270,7 @@ class DiaryEditScreen extends StatelessWidget { textInputAction: TextInputAction.done, ), Padding( - padding: EdgeInsets.only(left: 10.h), + padding: EdgeInsets.only(right: 30.h), child: Text( "порций", style: CustomTextStyles.bodyMediumBlack900, @@ -288,16 +279,28 @@ class DiaryEditScreen extends StatelessWidget { ), ), SizedBox(height: 30.v), - _buildAddProduct(context), SizedBox(height: 30.v), //_buildAddPhoto(context), - SizedBox(height: 29.v), Text( "Ваша сытость после приёма пищи", style: CustomTextStyles.bodyMediumBlack900, ), SizedBox(height: 15.v), + CustomDropDown( + icon: Container( + margin: EdgeInsets.fromLTRB(30.h, 30.v, 20.h, 30.v), + child: CustomImageView( + imagePath: ImageConstant.imgArrowLeft, + height: 10.v, + width: 18.h, + ), + ), + hintText: "Сытость", + items: satietyList, + borderDecoration: InputBorder.none, + onChanged: (value) {}, + ), ], ), )); @@ -736,77 +739,80 @@ class DiaryEditScreen extends StatelessWidget { bottom: 41.v, ), buttonStyle: CustomButtonStyles.outlinePrimaryTL15, + decoration: BoxDecoration( + color: Colors.transparent, + ), // Установите прозрачный фон ); } -} -Widget _buildMood( - List moodList, BuildContext context, DiaryEditLoadedState state) { - return Padding( - padding: EdgeInsets.symmetric(horizontal: 16.h), - child: Container( - padding: EdgeInsets.symmetric( - horizontal: 24.h, - vertical: 12.v, - ), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(12), - boxShadow: [ - BoxShadow( - color: Colors.grey.withOpacity(0.5), - spreadRadius: 2, - blurRadius: 5, - offset: Offset(0, 3), - ), - ], - ), - child: Column(children: [ - GestureDetector( - onTap: () { - /*BlocProvider.of(context) - .add(ToggleWakeupExpandedEvent());*/ - }, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Ваше настроение после приема пищи", - style: CustomTextStyles.bodyMediumBlack900, - ), - Icon(state.wakeupExpanded - ? Icons.arrow_drop_up - : Icons.arrow_drop_down), - ], - ), + Widget _buildMood( + List moodList, BuildContext context, DiaryEditLoadedState state) { + return Padding( + padding: EdgeInsets.symmetric(horizontal: 16.h), + child: Container( + padding: EdgeInsets.symmetric( + horizontal: 24.h, + vertical: 12.v, ), - if (state.moodExpanded) - CustomDropDown( - icon: Container( - margin: EdgeInsets.fromLTRB(30.h, 30.v, 20.h, 30.v), - child: CustomImageView( - imagePath: ImageConstant.imgArrowLeft, - height: 10.v, - width: 18.h, - ), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(12), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + spreadRadius: 2, + blurRadius: 5, + offset: Offset(0, 3), + ), + ], + ), + child: Column(children: [ + GestureDetector( + onTap: () { + /*BlocProvider.of(context) + .add(ToggleWakeupExpandedEvent());*/ + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Ваше настроение после приема пищи", + style: CustomTextStyles.bodyMediumBlack900, + ), + Icon(state.wakeupExpanded + ? Icons.arrow_drop_up + : Icons.arrow_drop_down), + ], ), - hintText: "Ваше настроение после приема пищи", - items: moodList, - onChanged: (value) {}, ), - ]))); -} - -Future _selectTime( - BuildContext context, DiaryEditLoadedState state) async { - final TimeOfDay? pickedTime = await showTimePicker( - context: context, - initialTime: state.wakeupController ?? TimeOfDay.now(), - ); - if (pickedTime != null && pickedTime != state.wakeupController) { - state.wakeupController = pickedTime; + if (state.moodExpanded) + CustomDropDown( + icon: Container( + margin: EdgeInsets.fromLTRB(30.h, 30.v, 20.h, 30.v), + child: CustomImageView( + imagePath: ImageConstant.imgArrowLeft, + height: 10.v, + width: 18.h, + ), + ), + hintText: "Ваше настроение после приема пищи", + items: moodList, + borderDecoration: InputBorder.none, + onChanged: (value) {}, + ), + ]))); + } + + Future _selectTime( + BuildContext context, DiaryEditLoadedState state) async { + final TimeOfDay? pickedTime = await showTimePicker( + context: context, + initialTime: state.wakeupController ?? TimeOfDay.now(), + ); + if (pickedTime != null && pickedTime != state.wakeupController) { + state.wakeupController = pickedTime; + } } -} /*Widget _buildImageStack(BuildContext context) { return Container( @@ -1032,4 +1038,5 @@ Future _selectTime( ], ), ); - }*/ \ No newline at end of file + }*/ +} diff --git a/lib/widgets/custom_edit_drop_down.dart b/lib/widgets/custom_edit_drop_down.dart index 9e22b9ab..e1ac863e 100644 --- a/lib/widgets/custom_edit_drop_down.dart +++ b/lib/widgets/custom_edit_drop_down.dart @@ -1,3 +1,4 @@ +import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; class CustomDropDown extends StatelessWidget { @@ -114,20 +115,17 @@ class CustomDropDown extends StatelessWidget { filled: filled, border: borderDecoration ?? OutlineInputBorder( - borderRadius: BorderRadius.circular(8), + borderRadius: BorderRadius.circular(8.h), borderSide: BorderSide.none, ), enabledBorder: borderDecoration ?? OutlineInputBorder( - borderRadius: BorderRadius.circular(8), + borderRadius: BorderRadius.circular(8.h), borderSide: BorderSide(color: Colors.grey, width: 1)), focusedBorder: borderDecoration ?? OutlineInputBorder( - borderRadius: BorderRadius.circular(5), - borderSide: BorderSide( - color: Colors.blue, - width: 1, - ), + borderRadius: BorderRadius.circular(5.h), + borderSide: BorderSide(color: Colors.grey, width: 1), ), ); } diff --git a/lib/widgets/custom_edit_text_form_field.dart b/lib/widgets/custom_edit_text_form_field.dart new file mode 100644 index 00000000..61f5b99c --- /dev/null +++ b/lib/widgets/custom_edit_text_form_field.dart @@ -0,0 +1,144 @@ +import 'package:eatvio_app/core/app_export.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +class CustomTextFormField extends StatelessWidget { + CustomTextFormField({ + Key? key, + this.alignment, + this.width, + this.controller, + this.focusNode, + this.autofocus = true, + this.textStyle, + this.obscureText = false, + this.textInputAction = TextInputAction.next, + this.textInputType = TextInputType.text, + this.maxLines, + this.hintText, + this.hintStyle, + this.prefix, + this.prefixConstraints, + this.suffix, + this.suffixConstraints, + this.contentPadding, + this.inputFormatters, + this.borderDecoration, + this.fillColor, + this.filled = true, + this.validator, + this.keyboardType, + this.onSaved, + }) : super( + key: key, + ); + + final Alignment? alignment; + + final double? width; + + final TextEditingController? controller; + + final FocusNode? focusNode; + + final bool? autofocus; + + final TextStyle? textStyle; + + final bool? obscureText; + + final List? inputFormatters; + + final TextInputAction? textInputAction; + + final TextInputType? textInputType; + + final int? maxLines; + + final String? hintText; + + final TextStyle? hintStyle; + + final Widget? prefix; + + final BoxConstraints? prefixConstraints; + + final Widget? suffix; + + final BoxConstraints? suffixConstraints; + + final EdgeInsets? contentPadding; + + final InputBorder? borderDecoration; + + final Color? fillColor; + + final bool? filled; + + final TextInputType? keyboardType; + + final FormFieldValidator? validator; + + final void Function(String?)? onSaved; + + @override + Widget build(BuildContext context) { + return alignment != null + ? Align( + alignment: alignment ?? Alignment.center, + child: textFormFieldWidget, + ) + : textFormFieldWidget; + } + + Widget get textFormFieldWidget => SizedBox( + width: width ?? double.maxFinite, + child: TextFormField( + controller: controller, + focusNode: focusNode ?? FocusNode(), + autofocus: autofocus!, + style: textStyle ?? theme.textTheme.titleMedium, + obscureText: obscureText!, + textInputAction: textInputAction, + maxLines: maxLines ?? 1, + decoration: decoration, + validator: validator, + keyboardType: keyboardType, + onSaved: onSaved, + inputFormatters: inputFormatters, + ), + ); + InputDecoration get decoration => InputDecoration( + hintText: hintText ?? "", + hintStyle: hintStyle ?? theme.textTheme.bodyLarge, + prefixIcon: prefix, + prefixIconConstraints: prefixConstraints, + suffixIcon: suffix, + suffixIconConstraints: suffixConstraints, + isDense: true, + contentPadding: contentPadding ?? EdgeInsets.all(6.h), + fillColor: fillColor ?? theme.colorScheme.onPrimary, + filled: filled, + border: borderDecoration ?? + OutlineInputBorder( + borderRadius: BorderRadius.circular(8.h), + borderSide: BorderSide(color: Colors.grey, width: 1), + ), + enabledBorder: borderDecoration ?? + OutlineInputBorder( + borderRadius: BorderRadius.circular(8.h), + borderSide: BorderSide( + color: Colors.grey, + width: 1, + ), + ), + focusedBorder: borderDecoration ?? + OutlineInputBorder( + borderRadius: BorderRadius.circular(8.h), + borderSide: BorderSide( + color: Colors.grey, + width: 1, + ), + ), + ); +} From 57a7f9bd9190445bf25d28b29ada5935728d9d9a Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 14 Feb 2024 14:56:16 +0300 Subject: [PATCH 07/32] feat(diary) Added controllers and improved form build logic --- .../bloc/diary_edit_bloc.dart | 20 ++++++++++++------- .../bloc/diary_edit_state.dart | 18 +++++++++++++++++ .../diary_edit_screen/diary_edit_screen.dart | 18 +++++++++++++---- pubspec.yaml | 1 + 4 files changed, 46 insertions(+), 11 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 98c218dd..801e28e3 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 @@ -41,14 +41,16 @@ class DiaryEditBloc extends Bloc { // Если текущее состояние уже загружено, обновляем его var currentState = state as DiaryEditLoadedState; // Обновляем значения контроллеров только если они уже были созданы - print(currentState.wakeupController); emit((currentState).copyWith( - wakeupExpanded: currentState.wakeupExpanded, - moodExpanded: currentState.moodExpanded, - wakeupController: currentState.wakeupController, - retireController: currentState.retireController, - commentController: currentState.commentController, - )); + wakeupExpanded: currentState.wakeupExpanded, + moodExpanded: currentState.moodExpanded, + wakeupController: currentState.wakeupController, + retireController: currentState.retireController, + commentController: currentState.commentController, + mealTimeController: currentState.mealTimeController, + mealNameController: currentState.mealNameController, + productNameController: currentState.productNameController, + productQuantityController: currentState.productQuantityController)); } else { // Если текущее состояние - начальное, создаем новое загруженное состояние emit(DiaryEditLoadedState( @@ -56,7 +58,11 @@ class DiaryEditBloc extends Bloc { moodExpanded: true, wakeupController: TimeOfDay.now(), retireController: TimeOfDay.now(), + mealTimeController: TimeOfDay.now(), + mealNameController: TextEditingController(), commentController: TextEditingController(), + productNameController: TextEditingController(), + productQuantityController: TextEditingController(), )); } /*} else { diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart index 28cdd066..23c56676 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart @@ -23,6 +23,10 @@ class DiaryEditLoadedState extends DiaryEditState { this.wakeupController, this.retireController, this.commentController, + this.mealTimeController, + this.mealNameController, + this.productNameController, + this.productQuantityController, required this.wakeupExpanded, required this.moodExpanded}) : super(diaryEditModelObj: null); @@ -30,7 +34,11 @@ class DiaryEditLoadedState extends DiaryEditState { DiaryEditModel? diaryEditModelObj; TimeOfDay? wakeupController; TimeOfDay? retireController; + TimeOfDay? mealTimeController; + TextEditingController? mealNameController; TextEditingController? commentController; + TextEditingController? productNameController; + TextEditingController? productQuantityController; bool wakeupExpanded; bool moodExpanded; @override @@ -40,7 +48,11 @@ class DiaryEditLoadedState extends DiaryEditState { DiaryEditModel? diaryEditModelObj, TimeOfDay? wakeupController, TimeOfDay? retireController, + TimeOfDay? mealTimeController, + TextEditingController? mealNameController, TextEditingController? commentController, + TextEditingController? productNameController, + TextEditingController? productQuantityController, required bool wakeupExpanded, required bool moodExpanded, }) { @@ -48,7 +60,13 @@ class DiaryEditLoadedState extends DiaryEditState { diaryEditModelObj: diaryEditModelObj ?? this.diaryEditModelObj, wakeupController: wakeupController ?? this.wakeupController, retireController: retireController ?? this.retireController, + mealTimeController: mealTimeController ?? this.mealTimeController, + mealNameController: mealNameController ?? this.mealNameController, commentController: commentController ?? this.commentController, + productNameController: + productNameController ?? this.productNameController, + productQuantityController: + productQuantityController ?? this.productQuantityController, wakeupExpanded: wakeupExpanded, moodExpanded: moodExpanded); } 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 d1b4c690..576a6677 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -1,6 +1,8 @@ import 'bloc/diary_edit_bloc.dart'; import 'models/diary_edit_model.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_form_builder/flutter_form_builder.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/widgets/custom_edit_text_form_field.dart'; import 'package:eatvio_app/widgets/custom_edit_drop_down.dart'; @@ -74,7 +76,8 @@ class DiaryEditScreen extends StatelessWidget { Widget _buildDiaryEditScreen( BuildContext context, DiaryEditLoadedState state) { mediaQueryData = MediaQuery.of(context); - return SafeArea( + return FormBuilder( + child: SafeArea( child: Scaffold( backgroundColor: Color.fromARGB(255, 240, 242, 245), resizeToAvoidBottomInset: true, @@ -110,7 +113,7 @@ class DiaryEditScreen extends StatelessWidget { ), bottomNavigationBar: _buildEndDay(context), ), - ); + )); } /// Section Widget @@ -193,6 +196,7 @@ class DiaryEditScreen extends StatelessWidget { } _buildMeal(BuildContext context, DiaryEditLoadedState state) { + final digitsOnly = FilteringTextInputFormatter.digitsOnly; return Padding( padding: EdgeInsets.symmetric(horizontal: 16.h), child: Container( @@ -230,8 +234,10 @@ class DiaryEditScreen extends StatelessWidget { constraints: BoxConstraints( maxWidth: MediaQuery.of(context).size.width - 247, ), - child: CustomTextFormField( - hintText: "14:52", + child: FormBuilderDateTimePicker( + name: 'mealTime', + inputType: InputType.time, + decoration: InputDecoration(), ), ), ), @@ -256,6 +262,7 @@ class DiaryEditScreen extends StatelessWidget { padding: EdgeInsets.symmetric(horizontal: 10.h), child: CustomTextFormField( hintText: "Введите названия продукта", + controller: state.productNameController, ), ), SizedBox(height: 20.v), @@ -268,6 +275,9 @@ class DiaryEditScreen extends StatelessWidget { width: 146.h, hintText: "Кол-во", textInputAction: TextInputAction.done, + controller: state.productQuantityController, + keyboardType: TextInputType.number, + inputFormatters: [digitsOnly], ), Padding( padding: EdgeInsets.only(right: 30.h), diff --git a/pubspec.yaml b/pubspec.yaml index 5bc2b5fc..756e9229 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,6 +23,7 @@ dependencies: flutter_spinkit: ^5.0.0 flutter_dotenv: ^5.1.0 carousel_slider: ^4.2.1 + flutter_form_builder: ^9.2.1 dev_dependencies: flutter_test: From 397b579e56f5d479dbefc9f0fb19725d54e8cf2a Mon Sep 17 00:00:00 2001 From: maxxkim Date: Thu, 15 Feb 2024 13:08:50 +0300 Subject: [PATCH 08/32] feat(diary) Addeed mood and satiety picker scale to the screen --- .../bloc/diary_edit_bloc.dart | 13 ++ .../bloc/diary_edit_event.dart | 8 ++ .../bloc/diary_edit_state.dart | 8 ++ .../diary_edit_screen/diary_edit_screen.dart | 126 ++++++++++++++---- lib/widgets/custom_scale_element.dart | 28 ++++ 5 files changed, 158 insertions(+), 25 deletions(-) create mode 100644 lib/widgets/custom_scale_element.dart 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 801e28e3..4b879c67 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 @@ -50,6 +50,8 @@ class DiaryEditBloc extends Bloc { mealTimeController: currentState.mealTimeController, mealNameController: currentState.mealNameController, productNameController: currentState.productNameController, + selectedSatiety: currentState.selectedSatiety, + selectedMood: currentState.selectedMood, productQuantityController: currentState.productQuantityController)); } else { // Если текущее состояние - начальное, создаем новое загруженное состояние @@ -59,6 +61,8 @@ class DiaryEditBloc extends Bloc { wakeupController: TimeOfDay.now(), retireController: TimeOfDay.now(), mealTimeController: TimeOfDay.now(), + selectedSatiety: 3, + selectedMood: 3, mealNameController: TextEditingController(), commentController: TextEditingController(), productNameController: TextEditingController(), @@ -85,3 +89,12 @@ class DiaryEditBloc extends Bloc { emit(state.copyWith(wakeupExpanded: !state.wakeupExpanded)); }*/ } + +class ScaleBloc extends Bloc { + ScaleBloc() : super(0); + + @override + Stream mapEventToState(ScaleEvent event) async* { + yield event.selectedElement; + } +} 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 183f4500..a95e6037 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,4 +15,12 @@ class DiaryEditInitialEvent extends DiaryEditEvent { List get props => []; } +class ScaleEvent extends Equatable { + final int selectedElement; + + ScaleEvent(this.selectedElement); + + @override + List get props => [selectedElement]; +} //class ToggleWakeupExpandedEvent extends DiaryEditEvent {} diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart index 23c56676..91570c27 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart @@ -27,6 +27,8 @@ class DiaryEditLoadedState extends DiaryEditState { this.mealNameController, this.productNameController, this.productQuantityController, + this.selectedMood, + required this.selectedSatiety, required this.wakeupExpanded, required this.moodExpanded}) : super(diaryEditModelObj: null); @@ -39,6 +41,8 @@ class DiaryEditLoadedState extends DiaryEditState { TextEditingController? commentController; TextEditingController? productNameController; TextEditingController? productQuantityController; + int? selectedMood; + int selectedSatiety; bool wakeupExpanded; bool moodExpanded; @override @@ -53,6 +57,8 @@ class DiaryEditLoadedState extends DiaryEditState { TextEditingController? commentController, TextEditingController? productNameController, TextEditingController? productQuantityController, + int? selectedMood, + required int selectedSatiety, required bool wakeupExpanded, required bool moodExpanded, }) { @@ -67,6 +73,8 @@ class DiaryEditLoadedState extends DiaryEditState { productNameController ?? this.productNameController, productQuantityController: productQuantityController ?? this.productQuantityController, + selectedMood: selectedMood ?? this.selectedMood, + selectedSatiety: selectedSatiety, wakeupExpanded: wakeupExpanded, moodExpanded: moodExpanded); } 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 576a6677..6924fe91 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -7,6 +7,7 @@ import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/widgets/custom_edit_text_form_field.dart'; import 'package:eatvio_app/widgets/custom_edit_drop_down.dart'; import 'package:eatvio_app/widgets/custom_outlined_button.dart'; +import 'package:eatvio_app/widgets/custom_scale_element.dart'; // ignore: must_be_immutable class DiaryEditScreen extends StatelessWidget { @@ -197,6 +198,7 @@ class DiaryEditScreen extends StatelessWidget { _buildMeal(BuildContext context, DiaryEditLoadedState state) { final digitsOnly = FilteringTextInputFormatter.digitsOnly; + final ScaleBloc scaleBloc = ScaleBloc(); return Padding( padding: EdgeInsets.symmetric(horizontal: 16.h), child: Container( @@ -297,20 +299,56 @@ class DiaryEditScreen extends StatelessWidget { style: CustomTextStyles.bodyMediumBlack900, ), SizedBox(height: 15.v), - CustomDropDown( - icon: Container( - margin: EdgeInsets.fromLTRB(30.h, 30.v, 20.h, 30.v), - child: CustomImageView( - imagePath: ImageConstant.imgArrowLeft, - height: 10.v, - width: 18.h, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text("😭"), + ScaleElement( + color: Colors.red, + isSelected: state.selectedSatiety == 0, + onTap: () { + scaleBloc.add(ScaleEvent(0)); + }, ), - ), - hintText: "Сытость", - items: satietyList, - borderDecoration: InputBorder.none, - onChanged: (value) {}, - ), + ScaleElement( + color: Colors.orange, + isSelected: state.selectedSatiety == 1, + onTap: () { + scaleBloc.add(ScaleEvent(1)); + }, + ), + ScaleElement( + color: Colors.yellow, + isSelected: state.selectedSatiety == 2, + onTap: () { + scaleBloc.add(ScaleEvent(2)); + }, + ), + ScaleElement( + color: Colors.lime, + isSelected: state.selectedSatiety == 3, + onTap: () { + scaleBloc.add(ScaleEvent(3)); + }, + ), + ScaleElement( + color: Colors.lightGreen, + isSelected: state.selectedSatiety == 4, + onTap: () { + scaleBloc.add(ScaleEvent(4)); + }, + ), + ScaleElement( + color: Colors.green, + isSelected: state.selectedSatiety == 5, + onTap: () { + scaleBloc.add(ScaleEvent(5)); + }, + ), + Text("😊"), + // Остальные элементы шкалы + ], + ) ], ), )); @@ -757,6 +795,8 @@ class DiaryEditScreen extends StatelessWidget { Widget _buildMood( List moodList, BuildContext context, DiaryEditLoadedState state) { + final ScaleBloc scaleBloc = ScaleBloc(); + return Padding( padding: EdgeInsets.symmetric(horizontal: 16.h), child: Container( @@ -796,19 +836,55 @@ class DiaryEditScreen extends StatelessWidget { ), ), if (state.moodExpanded) - CustomDropDown( - icon: Container( - margin: EdgeInsets.fromLTRB(30.h, 30.v, 20.h, 30.v), - child: CustomImageView( - imagePath: ImageConstant.imgArrowLeft, - height: 10.v, - width: 18.h, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text("😭"), + ScaleElement( + color: Colors.red, + isSelected: state.selectedMood == 0, + onTap: () { + scaleBloc.add(ScaleEvent(0)); + }, ), - ), - hintText: "Ваше настроение после приема пищи", - items: moodList, - borderDecoration: InputBorder.none, - onChanged: (value) {}, + ScaleElement( + color: Colors.orange, + isSelected: state.selectedMood == 1, + onTap: () { + scaleBloc.add(ScaleEvent(1)); + }, + ), + ScaleElement( + color: Colors.yellow, + isSelected: state.selectedMood == 2, + onTap: () { + scaleBloc.add(ScaleEvent(2)); + }, + ), + ScaleElement( + color: Colors.lime, + isSelected: state.selectedMood == 3, + onTap: () { + scaleBloc.add(ScaleEvent(3)); + }, + ), + ScaleElement( + color: Colors.lightGreen, + isSelected: state.selectedMood == 4, + onTap: () { + scaleBloc.add(ScaleEvent(4)); + }, + ), + ScaleElement( + color: Colors.green, + isSelected: state.selectedMood == 5, + onTap: () { + scaleBloc.add(ScaleEvent(5)); + }, + ), + Text("😊"), + // Остальные элементы шкалы + ], ), ]))); } diff --git a/lib/widgets/custom_scale_element.dart b/lib/widgets/custom_scale_element.dart new file mode 100644 index 00000000..531c95ef --- /dev/null +++ b/lib/widgets/custom_scale_element.dart @@ -0,0 +1,28 @@ +import 'package:flutter/material.dart'; + +class ScaleElement extends StatelessWidget { + final Color color; + final bool isSelected; + final VoidCallback onTap; + + const ScaleElement({ + required this.color, + required this.isSelected, + required this.onTap, + }); + + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: onTap, + child: Container( + width: isSelected ? 40 : 20, + height: isSelected ? 40 : 20, + decoration: BoxDecoration( + color: color, + shape: BoxShape.circle, + ), + ), + ); + } +} From 8e49d056c586c4032cb880fff6f2bbb1e997d126 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Thu, 15 Feb 2024 15:11:38 +0300 Subject: [PATCH 09/32] feat(diary) Made an event for satieety and mood change --- .../bloc/diary_edit_bloc.dart | 25 +++++-- .../bloc/diary_edit_event.dart | 11 +++- .../bloc/diary_edit_state.dart | 12 ++-- .../diary_edit_screen/diary_edit_screen.dart | 66 +++++-------------- 4 files changed, 50 insertions(+), 64 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 4b879c67..bd114b8e 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 @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import '/core/app_export.dart'; @@ -14,6 +16,8 @@ part 'diary_edit_state.dart'; class DiaryEditBloc extends Bloc { DiaryEditBloc(DiaryEditState initialState) : super(initialState) { on(_onInitialize); + on(_changeSatiety); + on(_changeMood); } Future _onInitialize( @@ -88,13 +92,22 @@ class DiaryEditBloc extends Bloc { ToggleWakeupExpandedEvent event, Emitter emit) { emit(state.copyWith(wakeupExpanded: !state.wakeupExpanded)); }*/ -} -class ScaleBloc extends Bloc { - ScaleBloc() : super(0); + Future _changeSatiety( + SatietyEvent event, Emitter emit) async { + if (state is DiaryEditLoadedState) { + var currentState = state as DiaryEditLoadedState; + emit(currentState.copyWith(selectedSatiety: event.selectedElement)); + currentState.selectedSatiety = event.selectedElement; + } + } - @override - Stream mapEventToState(ScaleEvent event) async* { - yield event.selectedElement; + Future _changeMood( + MoodEvent event, Emitter emit) async { + if (state is DiaryEditLoadedState) { + var currentState = state as DiaryEditLoadedState; + emit(currentState.copyWith(selectedMood: event.selectedElement)); + currentState.selectedMood = event.selectedElement; + } } } 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 a95e6037..d88fead6 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,10 +15,17 @@ class DiaryEditInitialEvent extends DiaryEditEvent { List get props => []; } -class ScaleEvent extends Equatable { +class SatietyEvent extends DiaryEditEvent { + SatietyEvent(this.selectedElement); final int selectedElement; - ScaleEvent(this.selectedElement); + @override + List get props => [selectedElement]; +} + +class MoodEvent extends DiaryEditEvent { + MoodEvent(this.selectedElement); + final int selectedElement; @override List get props => [selectedElement]; diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart index 91570c27..71ca214f 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart @@ -58,9 +58,9 @@ class DiaryEditLoadedState extends DiaryEditState { TextEditingController? productNameController, TextEditingController? productQuantityController, int? selectedMood, - required int selectedSatiety, - required bool wakeupExpanded, - required bool moodExpanded, + int? selectedSatiety, + bool? wakeupExpanded, + bool? moodExpanded, }) { return DiaryEditLoadedState( diaryEditModelObj: diaryEditModelObj ?? this.diaryEditModelObj, @@ -74,9 +74,9 @@ class DiaryEditLoadedState extends DiaryEditState { productQuantityController: productQuantityController ?? this.productQuantityController, selectedMood: selectedMood ?? this.selectedMood, - selectedSatiety: selectedSatiety, - wakeupExpanded: wakeupExpanded, - moodExpanded: moodExpanded); + selectedSatiety: selectedSatiety ?? this.selectedSatiety, + wakeupExpanded: wakeupExpanded ?? this.wakeupExpanded, + moodExpanded: moodExpanded ?? this.moodExpanded); } } 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 6924fe91..795a4a63 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -25,24 +25,6 @@ class DiaryEditScreen extends StatelessWidget { "Прием пищи 6", ]; - List satietyList = [ - "Ужасное", - "Плохое", - "Удовлетворительное", - "Нормальное", - "Хорошее", - "Прекрасное", - ]; - - List moodList = [ - "Ужасное", - "Плохое", - "Удовлетворительное", - "Нормальное", - "Хорошее", - "Прекрасное", - ]; - static Widget builder(BuildContext context) { return BlocProvider( create: (context) => @@ -99,7 +81,7 @@ class DiaryEditScreen extends StatelessWidget { //_buildImageStack(context), _buildMeal(context, state), SizedBox(height: 20.v), - _buildMood(moodList, context, state), + _buildMood(context, state), SizedBox(height: 30.v), _buildHeaderColumn(context), SizedBox(height: 30.v), @@ -198,7 +180,6 @@ class DiaryEditScreen extends StatelessWidget { _buildMeal(BuildContext context, DiaryEditLoadedState state) { final digitsOnly = FilteringTextInputFormatter.digitsOnly; - final ScaleBloc scaleBloc = ScaleBloc(); return Padding( padding: EdgeInsets.symmetric(horizontal: 16.h), child: Container( @@ -307,48 +288,48 @@ class DiaryEditScreen extends StatelessWidget { color: Colors.red, isSelected: state.selectedSatiety == 0, onTap: () { - scaleBloc.add(ScaleEvent(0)); + context.read().add(SatietyEvent(0)); }, ), ScaleElement( color: Colors.orange, isSelected: state.selectedSatiety == 1, onTap: () { - scaleBloc.add(ScaleEvent(1)); + context.read().add(SatietyEvent(1)); }, ), ScaleElement( color: Colors.yellow, isSelected: state.selectedSatiety == 2, onTap: () { - scaleBloc.add(ScaleEvent(2)); + context.read().add(SatietyEvent(2)); }, ), ScaleElement( color: Colors.lime, isSelected: state.selectedSatiety == 3, onTap: () { - scaleBloc.add(ScaleEvent(3)); + context.read().add(SatietyEvent(3)); }, ), ScaleElement( color: Colors.lightGreen, isSelected: state.selectedSatiety == 4, onTap: () { - scaleBloc.add(ScaleEvent(4)); + context.read().add(SatietyEvent(4)); }, ), ScaleElement( color: Colors.green, isSelected: state.selectedSatiety == 5, onTap: () { - scaleBloc.add(ScaleEvent(5)); + context.read().add(SatietyEvent(5)); }, ), Text("😊"), // Остальные элементы шкалы ], - ) + ), ], ), )); @@ -793,10 +774,7 @@ class DiaryEditScreen extends StatelessWidget { ); } - Widget _buildMood( - List moodList, BuildContext context, DiaryEditLoadedState state) { - final ScaleBloc scaleBloc = ScaleBloc(); - + Widget _buildMood(BuildContext context, DiaryEditLoadedState state) { return Padding( padding: EdgeInsets.symmetric(horizontal: 16.h), child: Container( @@ -829,7 +807,7 @@ class DiaryEditScreen extends StatelessWidget { "Ваше настроение после приема пищи", style: CustomTextStyles.bodyMediumBlack900, ), - Icon(state.wakeupExpanded + Icon(state.moodExpanded ? Icons.arrow_drop_up : Icons.arrow_drop_down), ], @@ -843,44 +821,32 @@ class DiaryEditScreen extends StatelessWidget { ScaleElement( color: Colors.red, isSelected: state.selectedMood == 0, - onTap: () { - scaleBloc.add(ScaleEvent(0)); - }, + onTap: () {}, ), ScaleElement( color: Colors.orange, isSelected: state.selectedMood == 1, - onTap: () { - scaleBloc.add(ScaleEvent(1)); - }, + onTap: () {}, ), ScaleElement( color: Colors.yellow, isSelected: state.selectedMood == 2, - onTap: () { - scaleBloc.add(ScaleEvent(2)); - }, + onTap: () {}, ), ScaleElement( color: Colors.lime, isSelected: state.selectedMood == 3, - onTap: () { - scaleBloc.add(ScaleEvent(3)); - }, + onTap: () {}, ), ScaleElement( color: Colors.lightGreen, isSelected: state.selectedMood == 4, - onTap: () { - scaleBloc.add(ScaleEvent(4)); - }, + onTap: () {}, ), ScaleElement( color: Colors.green, isSelected: state.selectedMood == 5, - onTap: () { - scaleBloc.add(ScaleEvent(5)); - }, + onTap: () {}, ), Text("😊"), // Остальные элементы шкалы From a6ab577d20151ded646d13da90478f3f7736ffe5 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Thu, 15 Feb 2024 16:02:13 +0300 Subject: [PATCH 10/32] 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, From 139f57e1b58759bb05b2e1bc52d14c5c2156a317 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Fri, 16 Feb 2024 13:27:21 +0300 Subject: [PATCH 11/32] feat(diary) More events for api methods. Stump for photo upload --- assets/images/img_2456927096976.svg | 15 ++++-- assets/images/img_logo_eatvio.svg | 20 ++++---- .../auth/auth_screen/auth_screen.dart | 2 +- .../bloc/diary_edit_bloc.dart | 51 +++++++++++++++++-- .../bloc/diary_edit_event.dart | 42 ++++++++++++++- .../diary_edit_screen/diary_edit_screen.dart | 40 ++++++++++----- 6 files changed, 137 insertions(+), 33 deletions(-) diff --git a/assets/images/img_2456927096976.svg b/assets/images/img_2456927096976.svg index 17ee6769..f869ff41 100644 --- a/assets/images/img_2456927096976.svg +++ b/assets/images/img_2456927096976.svg @@ -1,5 +1,12 @@ - - - - + + + + + + + + + + + diff --git a/assets/images/img_logo_eatvio.svg b/assets/images/img_logo_eatvio.svg index 701b5d1d..bc575bc9 100644 --- a/assets/images/img_logo_eatvio.svg +++ b/assets/images/img_logo_eatvio.svg @@ -1,12 +1,12 @@ - - - - - + + + + + + + + + + - - - - - diff --git a/lib/presentation/auth/auth_screen/auth_screen.dart b/lib/presentation/auth/auth_screen/auth_screen.dart index c037c382..4cbef203 100644 --- a/lib/presentation/auth/auth_screen/auth_screen.dart +++ b/lib/presentation/auth/auth_screen/auth_screen.dart @@ -103,7 +103,7 @@ class AuthScreen extends StatelessWidget { box.put('token', token); Navigator.pushNamed( context, - AppRoutes.diaryEdit, + AppRoutes.myProfile, ); } else { showDialog( 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 c460b0d1..04ea8ccd 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,9 +16,15 @@ part 'diary_edit_state.dart'; class DiaryEditBloc extends Bloc { DiaryEditBloc(DiaryEditState initialState) : super(initialState) { on(_onInitialize); - on(_changeSatiety); - on(_changeMood); + on(_changeSatiety); // пользователь нажимает на шкалу сытости + on(_changeMood); // пользователь нажимает на шкалу настроения + on(_changeWakeup); // пользователь выбирает время пробуждения + on(_changeRetire); // пользователь выбирает время отхода ко сну on(_toggleMood); + on(_toggleWakeup); + on(_addPortion); //пользователь нажимает "Добавить продукт" + on( + _removePortion); // пользователь нажимает на крестик около продукта } Future _onInitialize( @@ -105,7 +111,7 @@ class DiaryEditBloc extends Bloc { } Future _changeMood( - MoodEvent event, Emitter emit) async { + ChangeMood event, Emitter emit) async { if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; @@ -124,4 +130,43 @@ class DiaryEditBloc extends Bloc { print(currentState.moodExpanded); } } + + FutureOr _toggleWakeup( + ToggleWakeupExpandedEvent event, Emitter emit) { + if (state is DiaryEditLoadedState) { + var currentState = state as DiaryEditLoadedState; + + emit(currentState.copyWith(wakeupExpanded: !currentState.wakeupExpanded)); + currentState.wakeupExpanded = !currentState.wakeupExpanded; + print(currentState.wakeupExpanded); + } + } + + FutureOr _changeWakeup( + WakeupEvent event, Emitter emit) { + if (state is DiaryEditLoadedState) { + var currentState = state as DiaryEditLoadedState; + + emit(currentState.copyWith(wakeupController: event.selectedTime)); + currentState.wakeupController = event.selectedTime; + print(currentState.wakeupExpanded); + } + } + + FutureOr _changeRetire( + RetireEvent event, Emitter emit) { + if (state is DiaryEditLoadedState) { + var currentState = state as DiaryEditLoadedState; + + emit(currentState.copyWith(retireController: event.selectedTime)); + currentState.retireController = event.selectedTime; + print(currentState.retireController); + } + } + + FutureOr _addPortion( + AddPortionEvent event, Emitter emit) {} + + FutureOr _removePortion( + RemovePortionEvent event, Emitter emit) {} } 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 47c8994f..e91d1c99 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 @@ -23,15 +23,53 @@ class ChangeSatiety extends DiaryEditEvent { List get props => [selectedElement]; } -class MoodEvent extends DiaryEditEvent { - MoodEvent(this.selectedElement); +class ChangeMood extends DiaryEditEvent { + ChangeMood(this.selectedElement); final int selectedElement; @override List get props => [selectedElement]; } +class WakeupEvent extends DiaryEditEvent { + WakeupEvent(this.selectedTime); + final TimeOfDay selectedTime; + + @override + List get props => [selectedTime]; +} + +class RetireEvent extends DiaryEditEvent { + RetireEvent(this.selectedTime); + final TimeOfDay selectedTime; + + @override + List get props => [selectedTime]; +} + class ToggleMoodExpandedEvent extends DiaryEditEvent { @override List get props => []; } + +class ToggleWakeupExpandedEvent extends DiaryEditEvent { + @override + List get props => []; +} + +class AddPortionEvent extends DiaryEditEvent { + AddPortionEvent(this.mealId, this.productId, this.quantity, this.portion); + final int mealId; + final int productId; + final int quantity; + final String portion; + @override + List get props => [mealId, productId, quantity]; +} + +class RemovePortionEvent extends DiaryEditEvent { + RemovePortionEvent(this.portionId); + final int portionId; + @override + List get props => [portionId]; +} 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 469c9d1c..14685a2f 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -274,7 +274,9 @@ class DiaryEditScreen extends StatelessWidget { SizedBox(height: 30.v), _buildAddProduct(context), SizedBox(height: 30.v), - //_buildAddPhoto(context), + _buildProduct(context), + SizedBox(height: 30.v), + _buildAddPhoto(context), Text( "Ваша сытость после приёма пищи", style: CustomTextStyles.bodyMediumBlack900, @@ -363,7 +365,7 @@ class DiaryEditScreen extends StatelessWidget { top: 5.v, ), child: Text( - "Сырный суп", + "Omelette", style: CustomTextStyles.titleMedium16, ), ), @@ -374,7 +376,7 @@ class DiaryEditScreen extends StatelessWidget { bottom: 3.v, ), child: Text( - "400мл", + "15гр", style: CustomTextStyles.titleMedium16, ), ), @@ -713,8 +715,8 @@ class DiaryEditScreen extends StatelessWidget { children: [ GestureDetector( onTap: () { - /*BlocProvider.of(context) - .add(ToggleWakeupExpandedEvent());*/ + BlocProvider.of(context) + .add(ToggleWakeupExpandedEvent()); }, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -740,7 +742,7 @@ class DiaryEditScreen extends StatelessWidget { child: TextFormField( decoration: InputDecoration( labelText: 'Во сколько вы просунились?', - suffixIcon: Icon(Icons.access_time), + prefixIcon: Icon(Icons.sunny), ), initialValue: state.wakeupController.toString(), ), @@ -752,7 +754,7 @@ class DiaryEditScreen extends StatelessWidget { child: TextFormField( decoration: InputDecoration( labelText: 'Во сколько вы легли спать?', - suffixIcon: Icon(Icons.access_time), + prefixIcon: Icon(Icons.bed), ), initialValue: state.retireController.toString(), ), @@ -829,32 +831,44 @@ class DiaryEditScreen extends StatelessWidget { ScaleElement( color: Colors.red, isSelected: state.selectedMood == 0, - onTap: () {}, + onTap: () { + context.read().add(ChangeMood(0)); + }, ), ScaleElement( color: Colors.orange, isSelected: state.selectedMood == 1, - onTap: () {}, + onTap: () { + context.read().add(ChangeMood(1)); + }, ), ScaleElement( color: Colors.yellow, isSelected: state.selectedMood == 2, - onTap: () {}, + onTap: () { + context.read().add(ChangeMood(2)); + }, ), ScaleElement( color: Colors.lime, isSelected: state.selectedMood == 3, - onTap: () {}, + onTap: () { + context.read().add(ChangeMood(3)); + }, ), ScaleElement( color: Colors.lightGreen, isSelected: state.selectedMood == 4, - onTap: () {}, + onTap: () { + context.read().add(ChangeMood(4)); + }, ), ScaleElement( color: Colors.green, isSelected: state.selectedMood == 5, - onTap: () {}, + onTap: () { + context.read().add(ChangeMood(5)); + }, ), Text("😊"), // Остальные элементы шкалы From faf04393493683434217d39920d599295fef6294 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Fri, 16 Feb 2024 15:15:26 +0300 Subject: [PATCH 12/32] feat(diary) Image upload package and logic --- .../bloc/diary_edit_bloc.dart | 25 +++++++ .../bloc/diary_edit_event.dart | 7 ++ .../diary_edit_screen/diary_edit_screen.dart | 73 +++++++++++++------ lib/theme/custom_button_style.dart | 2 +- lib/widgets/custom_edit_drop_down.dart | 9 +-- pubspec.yaml | 1 + 6 files changed, 85 insertions(+), 32 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 04ea8ccd..efdde2ef 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 @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import '/core/app_export.dart'; +import 'package:image_picker/image_picker.dart'; import 'package:eatvio_app/presentation/diary/diary_edit_screen/models/diary_edit_model.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; @@ -25,6 +26,7 @@ class DiaryEditBloc extends Bloc { on(_addPortion); //пользователь нажимает "Добавить продукт" on( _removePortion); // пользователь нажимает на крестик около продукта + on(_uploadImages); //пользователь нажимает "Добавить продукт" } Future _onInitialize( @@ -169,4 +171,27 @@ class DiaryEditBloc extends Bloc { FutureOr _removePortion( RemovePortionEvent event, Emitter emit) {} + + Future> _uploadImages( + UploadImages event, Emitter emit) async { + String imageUrl = await uploadImageToServer(event.image.path); + print(imageUrl); + } +} + +Future uploadImageToServer(String imagePath) async { + var request = http.MultipartRequest( + 'POST', + Uri.parse('http://your-api-url.com/upload'), // Замените на ваш маршрут API + ); + + request.files.add(await http.MultipartFile.fromPath('image', imagePath)); + + var response = await request.send(); + if (response.statusCode == 200) { + var responseData = await response.stream.bytesToString(); + return responseData; + } else { + throw Exception('Ошибка при загрузке изображения'); + } } 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 e91d1c99..fcc57c64 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 @@ -73,3 +73,10 @@ class RemovePortionEvent extends DiaryEditEvent { @override List get props => [portionId]; } + +class UploadImages extends DiaryEditEvent { + UploadImages(this.image); + final XFile image; + @override + List get props => [image]; +} 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 14685a2f..6308623a 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -3,6 +3,7 @@ import 'models/diary_edit_model.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_form_builder/flutter_form_builder.dart'; +import 'package:image_picker/image_picker.dart'; import 'package:eatvio_app/core/app_export.dart'; import 'package:eatvio_app/widgets/custom_edit_text_form_field.dart'; import 'package:eatvio_app/widgets/custom_edit_drop_down.dart'; @@ -162,19 +163,47 @@ class DiaryEditScreen extends StatelessWidget { /// Section Widget Widget _buildAddPhoto(BuildContext context) { - return CustomOutlinedButton( - width: 195.h, - text: "Добавить фото", - rightIcon: Container( - margin: EdgeInsets.only(left: 14.h), - child: CustomImageView( - imagePath: ImageConstant.imgVector, - height: 30.v, - width: 34.h, + return GestureDetector( + onTap: () async { + final picker = ImagePicker(); + List? images = await picker.pickMultiImage(); + if (images.isNotEmpty) { + for (var image in images) { + context.read().add(UploadImages(image)); + } + } + }, + child: Container( + margin: EdgeInsets.symmetric(horizontal: 10.h), + padding: EdgeInsets.symmetric( + horizontal: 40.h, + vertical: 80.v, + ), + decoration: AppDecoration.fillGray.copyWith( + borderRadius: BorderRadiusStyle.roundedBorder5, + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: EdgeInsets.only( + left: 7.h, + top: 5.v, + ), + child: Text( + "Добавить фото", + selectionColor: appTheme.blueA400, + ), + ), + Spacer(), + Icon( + Icons.photo_library, + color: appTheme.blueGray300, + ) + ], ), ), - buttonStyle: CustomButtonStyles.outlinePrimaryTL15, - buttonTextStyle: theme.textTheme.bodyMedium!, ); } @@ -277,6 +306,7 @@ class DiaryEditScreen extends StatelessWidget { _buildProduct(context), SizedBox(height: 30.v), _buildAddPhoto(context), + SizedBox(height: 30.v), Text( "Ваша сытость после приёма пищи", style: CustomTextStyles.bodyMediumBlack900, @@ -365,7 +395,7 @@ class DiaryEditScreen extends StatelessWidget { top: 5.v, ), child: Text( - "Omelette", + "Сырный суп", style: CustomTextStyles.titleMedium16, ), ), @@ -377,21 +407,16 @@ class DiaryEditScreen extends StatelessWidget { ), child: Text( "15гр", - style: CustomTextStyles.titleMedium16, ), ), Spacer(), - CustomImageView( - imagePath: ImageConstant.imgSearch, - height: 24.adaptSize, - width: 24.adaptSize, - ), - CustomImageView( - imagePath: ImageConstant.imgClose, - height: 28.adaptSize, - width: 28.adaptSize, - margin: EdgeInsets.only(left: 10.h), - ), + Padding( + padding: const EdgeInsets.only(right: 10), + child: Icon( + Icons.close, + color: appTheme.blueGray300, + ), + ) ], ), ); diff --git a/lib/theme/custom_button_style.dart b/lib/theme/custom_button_style.dart index 95a5581e..bdd84d93 100644 --- a/lib/theme/custom_button_style.dart +++ b/lib/theme/custom_button_style.dart @@ -8,7 +8,7 @@ class CustomButtonStyles { backgroundColor: appTheme.blueA400, side: BorderSide( color: theme.colorScheme.primary, - width: 1, + width: 0, ), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(15.h), diff --git a/lib/widgets/custom_edit_drop_down.dart b/lib/widgets/custom_edit_drop_down.dart index e1ac863e..eecbea59 100644 --- a/lib/widgets/custom_edit_drop_down.dart +++ b/lib/widgets/custom_edit_drop_down.dart @@ -99,18 +99,13 @@ class CustomDropDown extends StatelessWidget { ); InputDecoration get decoration => InputDecoration( hintText: hintText ?? "", - hintStyle: hintStyle, + hintStyle: hintStyle ?? theme.textTheme.bodyLarge, prefixIcon: prefix, prefixIconConstraints: prefixConstraints, suffixIcon: suffix, suffixIconConstraints: suffixConstraints, isDense: true, - contentPadding: contentPadding ?? - EdgeInsets.only( - left: 17, - top: 17, - bottom: 17, - ), + contentPadding: contentPadding ?? EdgeInsets.all(6.h), fillColor: fillColor, filled: filled, border: borderDecoration ?? diff --git a/pubspec.yaml b/pubspec.yaml index 756e9229..711ce10f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -24,6 +24,7 @@ dependencies: flutter_dotenv: ^5.1.0 carousel_slider: ^4.2.1 flutter_form_builder: ^9.2.1 + image_picker: ^1.0.7 dev_dependencies: flutter_test: From 0091e00060992baf001c74f18c358b950c43928d Mon Sep 17 00:00:00 2001 From: maxxkim Date: Mon, 19 Feb 2024 09:28:25 +0300 Subject: [PATCH 13/32] feat(diary) dynnapic expandlists and mood/satiety scale --- .../bloc/diary_edit_bloc.dart | 20 ++++++++++--------- .../bloc/diary_edit_state.dart | 16 +++++++++++++-- 2 files changed, 25 insertions(+), 11 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 efdde2ef..b0b8b18b 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 @@ -26,7 +26,7 @@ class DiaryEditBloc extends Bloc { on(_addPortion); //пользователь нажимает "Добавить продукт" on( _removePortion); // пользователь нажимает на крестик около продукта - on(_uploadImages); //пользователь нажимает "Добавить продукт" + on(_uploadImages); //пользователь нажимает "Добавить фото" } Future _onInitialize( @@ -97,18 +97,16 @@ class DiaryEditBloc extends Bloc { }*/ } - /*_expandWakeup( - ToggleWakeupExpandedEvent event, Emitter emit) { - emit(state.copyWith(wakeupExpanded: !state.wakeupExpanded)); - }*/ - Future _changeSatiety( ChangeSatiety event, Emitter emit) async { if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; - emit(currentState.copyWith(selectedSatiety: event.selectedElement)); + var updatedState = + currentState.copyWith(selectedSatiety: event.selectedElement); + + emit(updatedState); // Передаем обновленное состояние в emit + currentState.selectedSatiety = event.selectedElement; - print(currentState.selectedSatiety); } } @@ -116,8 +114,11 @@ class DiaryEditBloc extends Bloc { ChangeMood event, Emitter emit) async { if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; + var updatedState = + currentState.copyWith(selectedMood: event.selectedElement); + + emit(updatedState); // Передаем обновленное состояние в emit - emit(currentState.copyWith(selectedMood: event.selectedElement)); currentState.selectedMood = event.selectedElement; } } @@ -129,6 +130,7 @@ class DiaryEditBloc extends Bloc { 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_state.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart index 71ca214f..457a8f25 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart @@ -46,8 +46,20 @@ class DiaryEditLoadedState extends DiaryEditState { bool wakeupExpanded; bool moodExpanded; @override - List get props => - [diaryEditModelObj, wakeupController, retireController]; + List get props => [ + diaryEditModelObj, + wakeupController, + retireController, + mealNameController, + mealTimeController, + commentController, + productNameController, + productQuantityController, + selectedMood, + selectedSatiety, + wakeupExpanded, + moodExpanded + ]; DiaryEditLoadedState copyWith({ DiaryEditModel? diaryEditModelObj, TimeOfDay? wakeupController, From 7d0de424882f183c432ddb776a04d1c7d1535ec1 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Mon, 19 Feb 2024 14:27:39 +0300 Subject: [PATCH 14/32] feat(diary) API methods added --- .../bloc/diary_edit_bloc.dart | 116 ++++++++++-------- .../bloc/diary_edit_event.dart | 31 +++-- .../bloc/diary_edit_state.dart | 10 ++ .../diary_edit_screen/diary_edit_screen.dart | 99 ++++++++++----- 4 files changed, 166 insertions(+), 90 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 b0b8b18b..37cab2b0 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 @@ -27,17 +27,16 @@ class DiaryEditBloc extends Bloc { on( _removePortion); // пользователь нажимает на крестик около продукта on(_uploadImages); //пользователь нажимает "Добавить фото" + on(_addComment); //пользователь нажимает "Добавить комментарий" } Future _onInitialize( DiaryEditInitialEvent event, Emitter emit, ) async { - /*try { - /*final box = await Hive.openBox('token'); - final token = box.get('token');*/ + try { final token = - "1|laravel_sanctum_JBjDvwoEpmFc7CmzBaktFtZPGfSpXcEVA5YgBQ380d322d92"; + "1|laravel_sanctum_8qeVUwDzs440SoG1pJFdSFtYWjJhZfEQXqStVkFPea8d4092"; final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/index'), headers: { @@ -47,42 +46,67 @@ class DiaryEditBloc extends Bloc { if (response.statusCode == 200) { final data = jsonDecode(response.body); - // Проверка наличия ключевых полей в JSON if (data is Map && data.containsKey('id')) { - // Все ключевые поля присутствуют, продолжаем обработку*/ - if (state is DiaryEditLoadedState) { - // Если текущее состояние уже загружено, обновляем его - var currentState = state as DiaryEditLoadedState; - // Обновляем значения контроллеров только если они уже были созданы - emit((currentState).copyWith( - wakeupExpanded: currentState.wakeupExpanded, - moodExpanded: currentState.moodExpanded, - wakeupController: currentState.wakeupController, - retireController: currentState.retireController, - commentController: currentState.commentController, - mealTimeController: currentState.mealTimeController, - mealNameController: currentState.mealNameController, - productNameController: currentState.productNameController, - selectedSatiety: currentState.selectedSatiety, - selectedMood: currentState.selectedMood, - productQuantityController: currentState.productQuantityController)); - } else { - // Если текущее состояние - начальное, создаем новое загруженное состояние - emit(DiaryEditLoadedState( - wakeupExpanded: true, - moodExpanded: true, - wakeupController: TimeOfDay.now(), - retireController: TimeOfDay.now(), - mealTimeController: TimeOfDay.now(), - selectedSatiety: 3, - selectedMood: 3, - mealNameController: TextEditingController(), - commentController: TextEditingController(), - productNameController: TextEditingController(), - productQuantityController: TextEditingController(), - )); - } - /*} else { + final int diaryId = data['id']; + try { + final response = await http.get( + Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/show/$diaryId'), + headers: { + 'Authorization': 'Bearer $token', + }, + ); + final diary = jsonDecode(response.body); + if (diary is Map) { + final String diaryDate = + diary['diary']['date'] ?? DateTime.now().toString(); + // Продолжайте обработку данных дневника + if (state is DiaryEditLoadedState) { + // Если текущее состояние уже загружено, обновляем его + var currentState = state as DiaryEditLoadedState; + emit((currentState).copyWith( + wakeupExpanded: currentState.wakeupExpanded, + moodExpanded: currentState.moodExpanded, + wakeupController: currentState.wakeupController, + retireController: currentState.retireController, + commentController: currentState.commentController, + mealTimeController: currentState.mealTimeController, + mealNameController: currentState.mealNameController, + productNameController: currentState.productNameController, + selectedSatiety: currentState.selectedSatiety, + selectedMood: currentState.selectedMood, + diaryDate: currentState.diaryDate, + productQuantityController: + currentState.productQuantityController, + )); + } else { + // Если текущее состояние - начальное, создаем новое загруженное состояние + emit(DiaryEditLoadedState( + wakeupExpanded: true, + moodExpanded: true, + wakeupController: TimeOfDay.now(), + retireController: TimeOfDay.now(), + mealTimeController: TimeOfDay.now(), + selectedSatiety: 3, + selectedMood: 3, + mealNameController: TextEditingController(), + commentController: TextEditingController(), + productNameController: TextEditingController(), + productQuantityController: TextEditingController(), + diaryId: diaryId, + diaryDate: diaryDate, + )); + } + } else { + // Ошибка при декодировании JSON + emit(DiaryEditErrorState( + 'Ошибка при декодировании данных дневника')); + } + } catch (e) { + // Ошибка при получении данных дневника + emit(DiaryEditErrorState( + 'Ошибка при получении данных дневника: $e')); + } + } else { // Один или несколько ключевых полей отсутствуют, обрабатываем ошибку emit( DiaryEditErrorState('Некоторые необходимые данные отсутствуют.')); @@ -92,9 +116,9 @@ class DiaryEditBloc extends Bloc { emit(DiaryEditErrorState('Ошибка сервера: ${response.statusCode}')); } } catch (e) { - // Ошибка при декодировании JSON или другая ошибка выполнения - emit(DiaryEditErrorState('Ошибка при получении данных профиля: $e')); - }*/ + // Ошибка при получении данных дневника + emit(DiaryEditErrorState('Ошибка при получении данных дневника: $e')); + } } Future _changeSatiety( @@ -130,8 +154,6 @@ class DiaryEditBloc extends Bloc { emit(currentState.copyWith(moodExpanded: !currentState.moodExpanded)); currentState.moodExpanded = !currentState.moodExpanded; - - print(currentState.moodExpanded); } } @@ -142,7 +164,6 @@ class DiaryEditBloc extends Bloc { emit(currentState.copyWith(wakeupExpanded: !currentState.wakeupExpanded)); currentState.wakeupExpanded = !currentState.wakeupExpanded; - print(currentState.wakeupExpanded); } } @@ -153,7 +174,6 @@ class DiaryEditBloc extends Bloc { emit(currentState.copyWith(wakeupController: event.selectedTime)); currentState.wakeupController = event.selectedTime; - print(currentState.wakeupExpanded); } } @@ -164,7 +184,6 @@ class DiaryEditBloc extends Bloc { emit(currentState.copyWith(retireController: event.selectedTime)); currentState.retireController = event.selectedTime; - print(currentState.retireController); } } @@ -177,8 +196,9 @@ class DiaryEditBloc extends Bloc { Future> _uploadImages( UploadImages event, Emitter emit) async { String imageUrl = await uploadImageToServer(event.image.path); - print(imageUrl); } + + FutureOr _addComment(AddComment event, Emitter emit) {} } Future uploadImageToServer(String imagePath) async { 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 fcc57c64..d010e840 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 @@ -16,35 +16,48 @@ class DiaryEditInitialEvent extends DiaryEditEvent { } class ChangeSatiety extends DiaryEditEvent { - ChangeSatiety(this.selectedElement); + ChangeSatiety(this.mealId, this.selectedElement); final int selectedElement; + final int mealId; @override - List get props => [selectedElement]; + List get props => [selectedElement, mealId]; } class ChangeMood extends DiaryEditEvent { - ChangeMood(this.selectedElement); + ChangeMood(this.diaryId, this.selectedElement); final int selectedElement; + final int diaryId; @override - List get props => [selectedElement]; + List get props => [selectedElement, diaryId]; +} + +class AddComment extends DiaryEditEvent { + AddComment(this.diaryId, this.comment); + final String comment; + final int diaryId; + + @override + List get props => [comment, diaryId]; } class WakeupEvent extends DiaryEditEvent { - WakeupEvent(this.selectedTime); + WakeupEvent(this.diaryId, this.selectedTime); final TimeOfDay selectedTime; + final int diaryId; @override - List get props => [selectedTime]; + List get props => [selectedTime, diaryId]; } class RetireEvent extends DiaryEditEvent { - RetireEvent(this.selectedTime); + RetireEvent(this.selectedTime, this.diaryId); final TimeOfDay selectedTime; + final int diaryId; @override - List get props => [selectedTime]; + List get props => [selectedTime, diaryId]; } class ToggleMoodExpandedEvent extends DiaryEditEvent { @@ -64,7 +77,7 @@ class AddPortionEvent extends DiaryEditEvent { final int quantity; final String portion; @override - List get props => [mealId, productId, quantity]; + List get props => [mealId, productId, quantity, portion]; } class RemovePortionEvent extends DiaryEditEvent { diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart index 457a8f25..96b8a48a 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart @@ -20,6 +20,7 @@ class DiaryEditInitialState extends DiaryEditState { class DiaryEditLoadedState extends DiaryEditState { DiaryEditLoadedState( {this.diaryEditModelObj, + this.diaryDate, this.wakeupController, this.retireController, this.commentController, @@ -28,12 +29,14 @@ class DiaryEditLoadedState extends DiaryEditState { this.productNameController, this.productQuantityController, this.selectedMood, + required this.diaryId, required this.selectedSatiety, required this.wakeupExpanded, required this.moodExpanded}) : super(diaryEditModelObj: null); DiaryEditModel? diaryEditModelObj; + String? diaryDate; TimeOfDay? wakeupController; TimeOfDay? retireController; TimeOfDay? mealTimeController; @@ -43,11 +46,13 @@ class DiaryEditLoadedState extends DiaryEditState { TextEditingController? productQuantityController; int? selectedMood; int selectedSatiety; + int diaryId; bool wakeupExpanded; bool moodExpanded; @override List get props => [ diaryEditModelObj, + diaryDate, wakeupController, retireController, mealNameController, @@ -57,11 +62,13 @@ class DiaryEditLoadedState extends DiaryEditState { productQuantityController, selectedMood, selectedSatiety, + diaryId, wakeupExpanded, moodExpanded ]; DiaryEditLoadedState copyWith({ DiaryEditModel? diaryEditModelObj, + String? diaryDate, TimeOfDay? wakeupController, TimeOfDay? retireController, TimeOfDay? mealTimeController, @@ -71,11 +78,13 @@ class DiaryEditLoadedState extends DiaryEditState { TextEditingController? productQuantityController, int? selectedMood, int? selectedSatiety, + int? diaryId, bool? wakeupExpanded, bool? moodExpanded, }) { return DiaryEditLoadedState( diaryEditModelObj: diaryEditModelObj ?? this.diaryEditModelObj, + diaryDate: diaryDate ?? this.diaryDate, wakeupController: wakeupController ?? this.wakeupController, retireController: retireController ?? this.retireController, mealTimeController: mealTimeController ?? this.mealTimeController, @@ -87,6 +96,7 @@ class DiaryEditLoadedState extends DiaryEditState { productQuantityController ?? this.productQuantityController, selectedMood: selectedMood ?? this.selectedMood, selectedSatiety: selectedSatiety ?? this.selectedSatiety, + diaryId: diaryId ?? this.diaryId, wakeupExpanded: wakeupExpanded ?? this.wakeupExpanded, moodExpanded: moodExpanded ?? this.moodExpanded); } 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 6308623a..7c33df93 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -75,7 +75,7 @@ class DiaryEditScreen extends StatelessWidget { padding: EdgeInsets.only(bottom: 5.v), child: Column( children: [ - _buildHeaderRow(context), + _buildHeaderRow(context, state), SizedBox(height: 30.v), _buildWakupRetire(context, state), SizedBox(height: 30.v), @@ -101,7 +101,7 @@ class DiaryEditScreen extends StatelessWidget { } /// Section Widget - Widget _buildHeaderRow(BuildContext context) { + Widget _buildHeaderRow(BuildContext context, DiaryEditLoadedState state) { return Container( margin: EdgeInsets.symmetric(horizontal: 16.h, vertical: 16.h), padding: EdgeInsets.symmetric( @@ -141,7 +141,7 @@ class DiaryEditScreen extends StatelessWidget { ), SizedBox(height: 2.v), Text( - "03-08-2023", + state.diaryDate.toString(), style: CustomTextStyles.bodyMediumBluegray800, ), ], @@ -244,12 +244,18 @@ class DiaryEditScreen extends StatelessWidget { padding: EdgeInsets.symmetric(horizontal: 10.h), child: ConstrainedBox( constraints: BoxConstraints( - maxWidth: MediaQuery.of(context).size.width - 247, + maxWidth: MediaQuery.of(context).size.width - 260, ), - child: FormBuilderDateTimePicker( - name: 'mealTime', - inputType: InputType.time, - decoration: InputDecoration(), + child: GestureDetector( + onTap: () => _selectTime(context, state), + child: AbsorbPointer( + child: CustomTextFormField( + hintText: state.mealTimeController + ?.format(context) + .toString(), + autofocus: false, + ), + ), ), ), ), @@ -323,42 +329,54 @@ class DiaryEditScreen extends StatelessWidget { color: Colors.red, isSelected: state.selectedSatiety == 0, onTap: () { - context.read().add(ChangeSatiety(0)); + context + .read() + .add(ChangeSatiety(0, state.diaryId)); }, ), ScaleElement( color: Colors.orange, isSelected: state.selectedSatiety == 1, onTap: () { - context.read().add(ChangeSatiety(1)); + context + .read() + .add(ChangeSatiety(1, state.diaryId)); }, ), ScaleElement( color: Colors.yellow, isSelected: state.selectedSatiety == 2, onTap: () { - context.read().add(ChangeSatiety(2)); + context + .read() + .add(ChangeSatiety(2, state.diaryId)); }, ), ScaleElement( color: Colors.lime, isSelected: state.selectedSatiety == 3, onTap: () { - context.read().add(ChangeSatiety(3)); + context + .read() + .add(ChangeSatiety(3, state.diaryId)); }, ), ScaleElement( color: Colors.lightGreen, isSelected: state.selectedSatiety == 4, onTap: () { - context.read().add(ChangeSatiety(4)); + context + .read() + .add(ChangeSatiety(4, state.diaryId)); }, ), ScaleElement( color: Colors.green, isSelected: state.selectedSatiety == 5, onTap: () { - context.read().add(ChangeSatiety(5)); + context + .read() + .add(ChangeSatiety(5, state.diaryId)); }, ), Text("😊"), @@ -761,30 +779,33 @@ class DiaryEditScreen extends StatelessWidget { padding: const EdgeInsets.only(left: 16.0), child: Column( children: [ + SizedBox(height: 20.v), GestureDetector( onTap: () => _selectTime(context, state), child: AbsorbPointer( - child: TextFormField( - decoration: InputDecoration( - labelText: 'Во сколько вы просунились?', - prefixIcon: Icon(Icons.sunny), - ), - initialValue: state.wakeupController.toString(), + child: CustomTextFormField( + hintText: state.wakeupController + ?.format(context) + .toString(), + prefix: Icon(Icons.sunny), + autofocus: false, ), ), ), + SizedBox(height: 20.v), GestureDetector( onTap: () => _selectTime(context, state), child: AbsorbPointer( - child: TextFormField( - decoration: InputDecoration( - labelText: 'Во сколько вы легли спать?', - prefixIcon: Icon(Icons.bed), - ), - initialValue: state.retireController.toString(), + child: CustomTextFormField( + hintText: state.retireController + ?.format(context) + .toString(), + prefix: Icon(Icons.bed), + autofocus: false, ), ), - ) + ), + SizedBox(height: 20.v), ], ), ), @@ -857,42 +878,54 @@ class DiaryEditScreen extends StatelessWidget { color: Colors.red, isSelected: state.selectedMood == 0, onTap: () { - context.read().add(ChangeMood(0)); + context + .read() + .add(ChangeMood(0, state.diaryId)); }, ), ScaleElement( color: Colors.orange, isSelected: state.selectedMood == 1, onTap: () { - context.read().add(ChangeMood(1)); + context + .read() + .add(ChangeMood(1, state.diaryId)); }, ), ScaleElement( color: Colors.yellow, isSelected: state.selectedMood == 2, onTap: () { - context.read().add(ChangeMood(2)); + context + .read() + .add(ChangeMood(2, state.diaryId)); }, ), ScaleElement( color: Colors.lime, isSelected: state.selectedMood == 3, onTap: () { - context.read().add(ChangeMood(3)); + context + .read() + .add(ChangeMood(3, state.diaryId)); }, ), ScaleElement( color: Colors.lightGreen, isSelected: state.selectedMood == 4, onTap: () { - context.read().add(ChangeMood(4)); + context + .read() + .add(ChangeMood(4, state.diaryId)); }, ), ScaleElement( color: Colors.green, isSelected: state.selectedMood == 5, onTap: () { - context.read().add(ChangeMood(5)); + context + .read() + .add(ChangeMood(5, state.diaryId)); }, ), Text("😊"), From ba6c0f06f673b69bd8078e234b8f637b49126248 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Mon, 19 Feb 2024 16:47:01 +0300 Subject: [PATCH 15/32] Meal time chhange front --- .../bloc/diary_edit_bloc.dart | 13 +++++++++++++ .../bloc/diary_edit_event.dart | 9 +++++++++ .../diary_edit_screen/diary_edit_screen.dart | 19 +++++++++++++------ lib/widgets/custom_edit_text_form_field.dart | 4 ++++ 4 files changed, 39 insertions(+), 6 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 37cab2b0..85a9bae9 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 @@ -19,6 +19,8 @@ class DiaryEditBloc extends Bloc { on(_onInitialize); on(_changeSatiety); // пользователь нажимает на шкалу сытости on(_changeMood); // пользователь нажимает на шкалу настроения + on( + _changeMealTime); // пользователь изменяет время приема пиши on(_changeWakeup); // пользователь выбирает время пробуждения on(_changeRetire); // пользователь выбирает время отхода ко сну on(_toggleMood); @@ -75,6 +77,7 @@ class DiaryEditBloc extends Bloc { selectedSatiety: currentState.selectedSatiety, selectedMood: currentState.selectedMood, diaryDate: currentState.diaryDate, + diaryId: currentState.diaryId, productQuantityController: currentState.productQuantityController, )); @@ -199,6 +202,16 @@ class DiaryEditBloc extends Bloc { } FutureOr _addComment(AddComment event, Emitter emit) {} + + FutureOr _changeMealTime( + ChangeMealTIme event, Emitter emit) { + if (state is DiaryEditLoadedState) { + var currentState = state as DiaryEditLoadedState; + + emit(currentState.copyWith(mealTimeController: event.time)); + currentState.mealTimeController = event.time; + } + } } Future uploadImageToServer(String imagePath) async { 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 d010e840..e117d080 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 @@ -33,6 +33,15 @@ class ChangeMood extends DiaryEditEvent { List get props => [selectedElement, diaryId]; } +class ChangeMealTIme extends DiaryEditEvent { + ChangeMealTIme(this.mealId, this.time); + final int mealId; + final TimeOfDay time; + + @override + List get props => [mealId, time]; +} + class AddComment extends DiaryEditEvent { AddComment(this.diaryId, this.comment); final String comment; 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 7c33df93..396f8d14 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -254,6 +254,7 @@ class DiaryEditScreen extends StatelessWidget { ?.format(context) .toString(), autofocus: false, + controller: state.mealTimeController, ), ), ), @@ -784,12 +785,14 @@ class DiaryEditScreen extends StatelessWidget { onTap: () => _selectTime(context, state), child: AbsorbPointer( child: CustomTextFormField( - hintText: state.wakeupController - ?.format(context) - .toString(), - prefix: Icon(Icons.sunny), - autofocus: false, - ), + hintText: state.wakeupController + ?.format(context) + .toString(), + prefix: Icon(Icons.sunny), + autofocus: false, + initialValue: state.wakeupController + ?.format(context) + .toString()), ), ), SizedBox(height: 20.v), @@ -802,6 +805,9 @@ class DiaryEditScreen extends StatelessWidget { .toString(), prefix: Icon(Icons.bed), autofocus: false, + initialValue: state.retireController + ?.format(context) + .toString(), ), ), ), @@ -943,6 +949,7 @@ class DiaryEditScreen extends StatelessWidget { ); if (pickedTime != null && pickedTime != state.wakeupController) { state.wakeupController = pickedTime; + context.read().add(ChangeMealTime(4, state.diaryId)); } } diff --git a/lib/widgets/custom_edit_text_form_field.dart b/lib/widgets/custom_edit_text_form_field.dart index 61f5b99c..5a5687fb 100644 --- a/lib/widgets/custom_edit_text_form_field.dart +++ b/lib/widgets/custom_edit_text_form_field.dart @@ -21,6 +21,7 @@ class CustomTextFormField extends StatelessWidget { this.prefixConstraints, this.suffix, this.suffixConstraints, + this.initialValue, this.contentPadding, this.inputFormatters, this.borderDecoration, @@ -77,6 +78,8 @@ class CustomTextFormField extends StatelessWidget { final TextInputType? keyboardType; + final String? initialValue; + final FormFieldValidator? validator; final void Function(String?)? onSaved; @@ -106,6 +109,7 @@ class CustomTextFormField extends StatelessWidget { keyboardType: keyboardType, onSaved: onSaved, inputFormatters: inputFormatters, + initialValue: initialValue, ), ); InputDecoration get decoration => InputDecoration( From c7e19718a3385c4f98d8b20f49972d9e074350b4 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Tue, 20 Feb 2024 10:14:00 +0300 Subject: [PATCH 16/32] feat(diary) Added a new event for meal time change --- README.md | 2 +- ios/Runner/Info.plist | 4 ++++ .../diary/diary_edit_screen/bloc/diary_edit_event.dart | 8 ++++++++ .../diary/diary_edit_screen/diary_edit_screen.dart | 3 +-- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 220ba3a6..f6cc1597 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ ### Как запускать? -Для запуска на эмуляторе в программе VS Code скомпилируйте и запустите файл main.dart (предварительно необходимо установить эмулятор в Android Studio) +Для запуска на эмуляторе в программе VS Code скомпилируйте и запустите файл main.dart (предварительно необходимо установить эмулятор в Android Studio или подключите устройство в режиме разработчика через USB) Для тестирования на устройствах Android в корневой папке проекта выполните команду diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index 08477d7a..8397f756 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -41,5 +41,9 @@ UIViewControllerBasedStatusBarAppearance + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + 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 e117d080..fbc32dff 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 @@ -102,3 +102,11 @@ class UploadImages extends DiaryEditEvent { @override List get props => [image]; } + +class ChangeMealTime extends DiaryEditEvent { + ChangeMealTime( this.time, this.diaryId, ); + final TimeOfDay time; + final int diaryId; + @override + List get props => [time, diaryId]; +} 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 396f8d14..05c18bd4 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -254,7 +254,6 @@ class DiaryEditScreen extends StatelessWidget { ?.format(context) .toString(), autofocus: false, - controller: state.mealTimeController, ), ), ), @@ -949,7 +948,7 @@ class DiaryEditScreen extends StatelessWidget { ); if (pickedTime != null && pickedTime != state.wakeupController) { state.wakeupController = pickedTime; - context.read().add(ChangeMealTime(4, state.diaryId)); + context.read().add(ChangeMealTime(pickedTime, state.diaryId)); } } From d2371ef8ce885a05d251310ccaf268fbb0cf4808 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Tue, 20 Feb 2024 10:18:23 +0300 Subject: [PATCH 17/32] fix(diary) No comment on this.. --- .../diary/diary_edit_screen/bloc/diary_edit_event.dart | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) 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 fbc32dff..b74bda47 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 @@ -33,7 +33,7 @@ class ChangeMood extends DiaryEditEvent { List get props => [selectedElement, diaryId]; } -class ChangeMealTIme extends DiaryEditEvent { +class ChangeMealTime extends DiaryEditEvent { ChangeMealTIme(this.mealId, this.time); final int mealId; final TimeOfDay time; @@ -102,11 +102,3 @@ class UploadImages extends DiaryEditEvent { @override List get props => [image]; } - -class ChangeMealTime extends DiaryEditEvent { - ChangeMealTime( this.time, this.diaryId, ); - final TimeOfDay time; - final int diaryId; - @override - List get props => [time, diaryId]; -} From 1903896cf6d8ecbffc7a3a744f70ec0b2a28c867 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Tue, 20 Feb 2024 10:22:15 +0300 Subject: [PATCH 18/32] fix(diary) fix --- .../diary/diary_edit_screen/bloc/diary_edit_event.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b74bda47..7bbdede0 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 @@ -34,7 +34,7 @@ class ChangeMood extends DiaryEditEvent { } class ChangeMealTime extends DiaryEditEvent { - ChangeMealTIme(this.mealId, this.time); + ChangeMealTime(this.mealId, this.time); final int mealId; final TimeOfDay time; From bd61687a960449560e46523dc0ba9fd07396c121 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Tue, 20 Feb 2024 10:23:10 +0300 Subject: [PATCH 19/32] fix(diary) fix --- .../diary/diary_edit_screen/bloc/diary_edit_bloc.dart | 4 ++-- .../diary/diary_edit_screen/diary_edit_screen.dart | 2 +- 2 files changed, 3 insertions(+), 3 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 85a9bae9..d5c81151 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 @@ -19,7 +19,7 @@ class DiaryEditBloc extends Bloc { on(_onInitialize); on(_changeSatiety); // пользователь нажимает на шкалу сытости on(_changeMood); // пользователь нажимает на шкалу настроения - on( + on( _changeMealTime); // пользователь изменяет время приема пиши on(_changeWakeup); // пользователь выбирает время пробуждения on(_changeRetire); // пользователь выбирает время отхода ко сну @@ -204,7 +204,7 @@ class DiaryEditBloc extends Bloc { FutureOr _addComment(AddComment event, Emitter emit) {} FutureOr _changeMealTime( - ChangeMealTIme event, Emitter emit) { + ChangeMealTime event, Emitter emit) { if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; 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 05c18bd4..a15d1a3a 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -948,7 +948,7 @@ class DiaryEditScreen extends StatelessWidget { ); if (pickedTime != null && pickedTime != state.wakeupController) { state.wakeupController = pickedTime; - context.read().add(ChangeMealTime(pickedTime, state.diaryId)); + context.read().add(ChangeMealTime(state.diaryId, pickedTime, )); } } From c46f612e1dd887bf6473506faa2bcafcb6a750bb Mon Sep 17 00:00:00 2001 From: maxxkim Date: Tue, 20 Feb 2024 10:27:42 +0300 Subject: [PATCH 20/32] refactor(diary) Podfile for iOS Cocoapods --- ios/Podfile | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 ios/Podfile diff --git a/ios/Podfile b/ios/Podfile new file mode 100644 index 00000000..d97f17e2 --- /dev/null +++ b/ios/Podfile @@ -0,0 +1,44 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '12.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) + target 'RunnerTests' do + inherit! :search_paths + end +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end From f52c929b208770fa7997af981a20af97f9362f71 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Tue, 20 Feb 2024 15:27:07 +0300 Subject: [PATCH 21/32] feat(diary) New time convert function, comment display and more --- .../bloc/diary_edit_bloc.dart | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 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 d5c81151..9c342c0c 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 @@ -57,10 +57,11 @@ class DiaryEditBloc extends Bloc { 'Authorization': 'Bearer $token', }, ); - final diary = jsonDecode(response.body); + final diary = jsonDecode(response.body)['diary']; if (diary is Map) { + print(diary); final String diaryDate = - diary['diary']['date'] ?? DateTime.now().toString(); + diary['date'] ?? DateTime.now().toString(); // Продолжайте обработку данных дневника if (state is DiaryEditLoadedState) { // Если текущее состояние уже загружено, обновляем его @@ -86,13 +87,14 @@ class DiaryEditBloc extends Bloc { emit(DiaryEditLoadedState( wakeupExpanded: true, moodExpanded: true, - wakeupController: TimeOfDay.now(), - retireController: TimeOfDay.now(), + wakeupController: toTime(diary['wakeup']), + retireController: toTime(diary['retire']), mealTimeController: TimeOfDay.now(), selectedSatiety: 3, selectedMood: 3, mealNameController: TextEditingController(), - commentController: TextEditingController(), + commentController: + TextEditingController(text: diary['comment']), productNameController: TextEditingController(), productQuantityController: TextEditingController(), diaryId: diaryId, @@ -230,3 +232,12 @@ Future uploadImageToServer(String imagePath) async { throw Exception('Ошибка при загрузке изображения'); } } + +TimeOfDay toTime(String timeStr) { + List timeParts = timeStr.split(":"); + int hour = int.parse(timeParts[0]); + int minute = int.parse(timeParts[1]); + + TimeOfDay timeOfDay = TimeOfDay(hour: hour, minute: minute); + return timeOfDay; +} From 3e4b683c33d62603462874a80054d7bb74a29c45 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Tue, 20 Feb 2024 15:57:15 +0300 Subject: [PATCH 22/32] feat(diary) Dynamic Meal list and Meal List object --- .../bloc/diary_edit_bloc.dart | 14 +++++ .../bloc/diary_edit_event.dart | 11 ++++ .../bloc/diary_edit_state.dart | 7 ++- .../diary_edit_screen/diary_edit_screen.dart | 44 ++++++++-------- .../models/diary_edit_model.dart | 10 ++-- lib/widgets/custom_edit_drop_down.dart | 51 ++++++++++++------- 6 files changed, 95 insertions(+), 42 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 9c342c0c..53446fc7 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 @@ -21,6 +21,7 @@ class DiaryEditBloc extends Bloc { on(_changeMood); // пользователь нажимает на шкалу настроения on( _changeMealTime); // пользователь изменяет время приема пиши + on(_changeMeal); on(_changeWakeup); // пользователь выбирает время пробуждения on(_changeRetire); // пользователь выбирает время отхода ко сну on(_toggleMood); @@ -214,6 +215,8 @@ class DiaryEditBloc extends Bloc { currentState.mealTimeController = event.time; } } + + FutureOr _changeMeal(ChangeMeal event, Emitter emit) {} } Future uploadImageToServer(String imagePath) async { @@ -241,3 +244,14 @@ TimeOfDay toTime(String timeStr) { TimeOfDay timeOfDay = TimeOfDay(hour: hour, minute: minute); return timeOfDay; } + +List fillMealList() { + return [ + SelectionPopupModel(id: 0, title: "Прием пищи 1", isSelected: true), + SelectionPopupModel(id: 1, title: "Прием пищи 2"), + SelectionPopupModel(id: 2, title: "Прием пищи 3"), + SelectionPopupModel(id: 3, title: "Прием пищи 4"), + SelectionPopupModel(id: 4, title: "Прием пищи 5"), + SelectionPopupModel(id: 5, title: "Прием пищи 6"), + ]; +} 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 7bbdede0..58e8c4ab 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 @@ -102,3 +102,14 @@ class UploadImages extends DiaryEditEvent { @override List get props => [image]; } + +class ChangeMeal extends DiaryEditEvent { + ChangeMeal({required this.value}); + + SelectionPopupModel value; + + @override + List get props => [ + value, + ]; +} diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart index 96b8a48a..85c9b104 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart @@ -29,6 +29,7 @@ class DiaryEditLoadedState extends DiaryEditState { this.productNameController, this.productQuantityController, this.selectedMood, + this.currentMeal, required this.diaryId, required this.selectedSatiety, required this.wakeupExpanded, @@ -37,6 +38,7 @@ class DiaryEditLoadedState extends DiaryEditState { DiaryEditModel? diaryEditModelObj; String? diaryDate; + SelectionPopupModel? currentMeal; TimeOfDay? wakeupController; TimeOfDay? retireController; TimeOfDay? mealTimeController; @@ -64,10 +66,12 @@ class DiaryEditLoadedState extends DiaryEditState { selectedSatiety, diaryId, wakeupExpanded, - moodExpanded + moodExpanded, + currentMeal ]; DiaryEditLoadedState copyWith({ DiaryEditModel? diaryEditModelObj, + SelectionPopupModel? currentMeal, String? diaryDate, TimeOfDay? wakeupController, TimeOfDay? retireController, @@ -97,6 +101,7 @@ class DiaryEditLoadedState extends DiaryEditState { selectedMood: selectedMood ?? this.selectedMood, selectedSatiety: selectedSatiety ?? this.selectedSatiety, diaryId: diaryId ?? this.diaryId, + currentMeal: currentMeal ?? this.currentMeal, wakeupExpanded: wakeupExpanded ?? this.wakeupExpanded, moodExpanded: moodExpanded ?? this.moodExpanded); } 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 a15d1a3a..fffaa692 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -17,15 +17,6 @@ class DiaryEditScreen extends StatelessWidget { key: key, ); - List mealList = [ - "Прием пищи 1", - "Прием пищи 2", - "Прием пищи 3", - "Прием пищи 4", - "Прием пищи 5", - "Прием пищи 6", - ]; - static Widget builder(BuildContext context) { return BlocProvider( create: (context) => @@ -264,17 +255,25 @@ class DiaryEditScreen extends StatelessWidget { ), SizedBox(height: 20.v), Padding( - padding: EdgeInsets.symmetric(horizontal: 10.h), - child: CustomDropDown( - hintText: "Прием пищи", - items: mealList, - contentPadding: EdgeInsets.symmetric( - horizontal: 10.h, - vertical: 9.v, - ), - onChanged: (value) {}, - ), - ), + padding: EdgeInsets.symmetric(horizontal: 10.h), + child: BlocSelector( + selector: (state) => state.diaryEditModelObj, + builder: (context, diaryEditModelObj) { + return CustomDropDown( + hintText: "Прием пищи", + items: diaryEditModelObj?.mealList, + contentPadding: EdgeInsets.symmetric( + horizontal: 10.h, + vertical: 9.v, + ), + onChanged: (value) { + context + .read() + .add(ChangeMeal(value: value)); + }, + ); + })), SizedBox(height: 20.v), Padding( padding: EdgeInsets.symmetric(horizontal: 10.h), @@ -948,7 +947,10 @@ class DiaryEditScreen extends StatelessWidget { ); if (pickedTime != null && pickedTime != state.wakeupController) { state.wakeupController = pickedTime; - context.read().add(ChangeMealTime(state.diaryId, pickedTime, )); + context.read().add(ChangeMealTime( + state.diaryId, + pickedTime, + )); } } diff --git a/lib/presentation/diary/diary_edit_screen/models/diary_edit_model.dart b/lib/presentation/diary/diary_edit_screen/models/diary_edit_model.dart index b2aaf181..32afe5d1 100644 --- a/lib/presentation/diary/diary_edit_screen/models/diary_edit_model.dart +++ b/lib/presentation/diary/diary_edit_screen/models/diary_edit_model.dart @@ -1,16 +1,20 @@ // ignore_for_file: must_be_immutable import 'package:equatable/equatable.dart'; +import 'package:eatvio_app/data/models/selectionPopupModel/selection_popup_model.dart'; /// This class defines the variables used in the [k0_page], /// and is typically used to hold data that is passed between different parts of the application. class DiaryEditModel extends Equatable { - DiaryEditModel(); + DiaryEditModel({this.mealList = const []}); + List mealList; DiaryEditModel copyWith() { - return DiaryEditModel(); + return DiaryEditModel( + mealList: mealList, + ); } @override - List get props => []; + List get props => [mealList]; } diff --git a/lib/widgets/custom_edit_drop_down.dart b/lib/widgets/custom_edit_drop_down.dart index eecbea59..67a2a1f9 100644 --- a/lib/widgets/custom_edit_drop_down.dart +++ b/lib/widgets/custom_edit_drop_down.dart @@ -39,7 +39,7 @@ class CustomDropDown extends StatelessWidget { final TextStyle? textStyle; - final List? items; + final List? items; final String? hintText; @@ -61,9 +61,9 @@ class CustomDropDown extends StatelessWidget { final bool? filled; - final FormFieldValidator? validator; + final FormFieldValidator? validator; - final Function(String)? onChanged; + final Function(SelectionPopupModel)? onChanged; @override Widget build(BuildContext context) { @@ -77,50 +77,67 @@ class CustomDropDown extends StatelessWidget { Widget get dropDownWidget => SizedBox( width: width ?? double.maxFinite, - child: DropdownButtonFormField( + child: DropdownButtonFormField( focusNode: focusNode ?? FocusNode(), icon: icon, autofocus: autofocus!, - items: items?.map>((String value) { - return DropdownMenuItem( - value: value, + style: textStyle ?? theme.textTheme.titleMedium, + items: items?.map((SelectionPopupModel item) { + return DropdownMenuItem( + value: item, child: Text( - value, + item.title, overflow: TextOverflow.ellipsis, + style: hintStyle ?? theme.textTheme.titleMedium, ), ); }).toList(), decoration: decoration, validator: validator, onChanged: (value) { - onChanged!(value.toString()); + onChanged!(value!); }, ), ); InputDecoration get decoration => InputDecoration( hintText: hintText ?? "", - hintStyle: hintStyle ?? theme.textTheme.bodyLarge, + hintStyle: hintStyle ?? theme.textTheme.titleMedium, prefixIcon: prefix, prefixIconConstraints: prefixConstraints, suffixIcon: suffix, suffixIconConstraints: suffixConstraints, isDense: true, - contentPadding: contentPadding ?? EdgeInsets.all(6.h), - fillColor: fillColor, + contentPadding: contentPadding ?? + EdgeInsets.only( + left: 6.h, + top: 6.v, + bottom: 6.v, + ), + fillColor: fillColor ?? theme.colorScheme.onPrimary, filled: filled, border: borderDecoration ?? OutlineInputBorder( borderRadius: BorderRadius.circular(8.h), - borderSide: BorderSide.none, + borderSide: BorderSide( + color: Colors.grey, + width: 1, + ), ), enabledBorder: borderDecoration ?? OutlineInputBorder( - borderRadius: BorderRadius.circular(8.h), - borderSide: BorderSide(color: Colors.grey, width: 1)), + borderRadius: BorderRadius.circular(8.h), + borderSide: BorderSide( + color: Colors.grey, + width: 1, + ), + ), focusedBorder: borderDecoration ?? OutlineInputBorder( - borderRadius: BorderRadius.circular(5.h), - borderSide: BorderSide(color: Colors.grey, width: 1), + borderRadius: BorderRadius.circular(8.h), + borderSide: BorderSide( + color: Colors.grey, + width: 1, + ), ), ); } From 6d04d1a688b05a8fcb978ff76cd6035f272e5313 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Tue, 20 Feb 2024 19:53:07 +0300 Subject: [PATCH 23/32] fix(diary) Fix meal list --- .../diary_edit_screen/bloc/diary_edit_bloc.dart | 13 ++++++++++--- .../diary_edit_screen/bloc/diary_edit_state.dart | 5 ----- 2 files changed, 10 insertions(+), 8 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 53446fc7..5f81f679 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 @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:ffi'; import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; @@ -74,7 +75,6 @@ class DiaryEditBloc extends Bloc { retireController: currentState.retireController, commentController: currentState.commentController, mealTimeController: currentState.mealTimeController, - mealNameController: currentState.mealNameController, productNameController: currentState.productNameController, selectedSatiety: currentState.selectedSatiety, selectedMood: currentState.selectedMood, @@ -93,7 +93,6 @@ class DiaryEditBloc extends Bloc { mealTimeController: TimeOfDay.now(), selectedSatiety: 3, selectedMood: 3, - mealNameController: TextEditingController(), commentController: TextEditingController(text: diary['comment']), productNameController: TextEditingController(), @@ -202,6 +201,7 @@ class DiaryEditBloc extends Bloc { Future> _uploadImages( UploadImages event, Emitter emit) async { String imageUrl = await uploadImageToServer(event.image.path); + print(imageUrl); } FutureOr _addComment(AddComment event, Emitter emit) {} @@ -216,7 +216,14 @@ class DiaryEditBloc extends Bloc { } } - FutureOr _changeMeal(ChangeMeal event, Emitter emit) {} + FutureOr _changeMeal(ChangeMeal event, Emitter emit) { + if (state is DiaryEditLoadedState) { + var currentState = state as DiaryEditLoadedState; + + emit(currentState.copyWith(currentMeal: event.value)); + currentState.currentMeal = event.value; + } + } } Future uploadImageToServer(String imagePath) async { diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart index 85c9b104..9829e1b8 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart @@ -25,7 +25,6 @@ class DiaryEditLoadedState extends DiaryEditState { this.retireController, this.commentController, this.mealTimeController, - this.mealNameController, this.productNameController, this.productQuantityController, this.selectedMood, @@ -42,7 +41,6 @@ class DiaryEditLoadedState extends DiaryEditState { TimeOfDay? wakeupController; TimeOfDay? retireController; TimeOfDay? mealTimeController; - TextEditingController? mealNameController; TextEditingController? commentController; TextEditingController? productNameController; TextEditingController? productQuantityController; @@ -57,7 +55,6 @@ class DiaryEditLoadedState extends DiaryEditState { diaryDate, wakeupController, retireController, - mealNameController, mealTimeController, commentController, productNameController, @@ -76,7 +73,6 @@ class DiaryEditLoadedState extends DiaryEditState { TimeOfDay? wakeupController, TimeOfDay? retireController, TimeOfDay? mealTimeController, - TextEditingController? mealNameController, TextEditingController? commentController, TextEditingController? productNameController, TextEditingController? productQuantityController, @@ -92,7 +88,6 @@ class DiaryEditLoadedState extends DiaryEditState { wakeupController: wakeupController ?? this.wakeupController, retireController: retireController ?? this.retireController, mealTimeController: mealTimeController ?? this.mealTimeController, - mealNameController: mealNameController ?? this.mealNameController, commentController: commentController ?? this.commentController, productNameController: productNameController ?? this.productNameController, From 65c465ab9d7f2035741614d75bf92601505bc371 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 21 Feb 2024 12:18:25 +0300 Subject: [PATCH 24/32] refactor(diary) Prepared front-end methods for API intergration --- .../bloc/diary_edit_bloc.dart | 65 ++-- .../bloc/diary_edit_event.dart | 10 +- .../bloc/diary_edit_state.dart | 9 + .../diary_edit_screen/diary_edit_screen.dart | 284 +++--------------- .../models/diary_edit_model.dart | 6 +- 5 files changed, 103 insertions(+), 271 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 5f81f679..2a912026 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 @@ -69,37 +69,42 @@ class DiaryEditBloc extends Bloc { // Если текущее состояние уже загружено, обновляем его var currentState = state as DiaryEditLoadedState; emit((currentState).copyWith( - wakeupExpanded: currentState.wakeupExpanded, - moodExpanded: currentState.moodExpanded, - wakeupController: currentState.wakeupController, - retireController: currentState.retireController, - commentController: currentState.commentController, - mealTimeController: currentState.mealTimeController, - productNameController: currentState.productNameController, - selectedSatiety: currentState.selectedSatiety, - selectedMood: currentState.selectedMood, - diaryDate: currentState.diaryDate, - diaryId: currentState.diaryId, - productQuantityController: - currentState.productQuantityController, - )); + wakeupExpanded: currentState.wakeupExpanded, + moodExpanded: currentState.moodExpanded, + token: currentState.token, + meals: currentState.meals, + wakeupController: currentState.wakeupController, + retireController: currentState.retireController, + commentController: currentState.commentController, + mealTimeController: currentState.mealTimeController, + productNameController: currentState.productNameController, + selectedSatiety: currentState.selectedSatiety, + selectedMood: currentState.selectedMood, + diaryDate: currentState.diaryDate, + diaryId: currentState.diaryId, + productQuantityController: + currentState.productQuantityController, + diaryEditModelObj: currentState.diaryEditModelObj)); } else { // Если текущее состояние - начальное, создаем новое загруженное состояние emit(DiaryEditLoadedState( - wakeupExpanded: true, - moodExpanded: true, - wakeupController: toTime(diary['wakeup']), - retireController: toTime(diary['retire']), - mealTimeController: TimeOfDay.now(), - selectedSatiety: 3, - selectedMood: 3, - commentController: - TextEditingController(text: diary['comment']), - productNameController: TextEditingController(), - productQuantityController: TextEditingController(), - diaryId: diaryId, - diaryDate: diaryDate, - )); + wakeupExpanded: true, + moodExpanded: true, + token: token, + meals: diary['meals'], + wakeupController: toTime(diary['wakeup'] ?? "09:00"), + retireController: toTime(diary['retire'] ?? "23:00"), + mealTimeController: TimeOfDay.now(), + selectedSatiety: 3, + selectedMood: 3, + commentController: + TextEditingController(text: diary['comment']), + productNameController: TextEditingController(), + productQuantityController: TextEditingController(), + diaryId: diaryId, + diaryDate: diaryDate, + diaryEditModelObj: state.diaryEditModelObj + ?.copyWith(mealList: fillMealList()))); } } else { // Ошибка при декодировании JSON @@ -149,6 +154,7 @@ class DiaryEditBloc extends Bloc { emit(updatedState); // Передаем обновленное состояние в emit currentState.selectedMood = event.selectedElement; + print(currentState.mealTimeController); } } @@ -179,6 +185,7 @@ class DiaryEditBloc extends Bloc { emit(currentState.copyWith(wakeupController: event.selectedTime)); currentState.wakeupController = event.selectedTime; + print(currentState.wakeupController); } } @@ -189,6 +196,7 @@ class DiaryEditBloc extends Bloc { emit(currentState.copyWith(retireController: event.selectedTime)); currentState.retireController = event.selectedTime; + print(currentState.retireController); } } @@ -213,6 +221,7 @@ class DiaryEditBloc extends Bloc { emit(currentState.copyWith(mealTimeController: event.time)); currentState.mealTimeController = event.time; + print(currentState.mealTimeController); } } 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 58e8c4ab..ab16a29a 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 @@ -16,7 +16,10 @@ class DiaryEditInitialEvent extends DiaryEditEvent { } class ChangeSatiety extends DiaryEditEvent { - ChangeSatiety(this.mealId, this.selectedElement); + ChangeSatiety( + this.selectedElement, + this.mealId, + ); final int selectedElement; final int mealId; @@ -25,7 +28,10 @@ class ChangeSatiety extends DiaryEditEvent { } class ChangeMood extends DiaryEditEvent { - ChangeMood(this.diaryId, this.selectedElement); + ChangeMood( + this.selectedElement, + this.diaryId, + ); final int selectedElement; final int diaryId; diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart index 9829e1b8..6485475d 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart @@ -21,6 +21,8 @@ class DiaryEditLoadedState extends DiaryEditState { DiaryEditLoadedState( {this.diaryEditModelObj, this.diaryDate, + this.token, + this.meals, this.wakeupController, this.retireController, this.commentController, @@ -37,6 +39,8 @@ class DiaryEditLoadedState extends DiaryEditState { DiaryEditModel? diaryEditModelObj; String? diaryDate; + String? token; + List? meals; SelectionPopupModel? currentMeal; TimeOfDay? wakeupController; TimeOfDay? retireController; @@ -53,6 +57,7 @@ class DiaryEditLoadedState extends DiaryEditState { List get props => [ diaryEditModelObj, diaryDate, + token, wakeupController, retireController, mealTimeController, @@ -70,6 +75,8 @@ class DiaryEditLoadedState extends DiaryEditState { DiaryEditModel? diaryEditModelObj, SelectionPopupModel? currentMeal, String? diaryDate, + String? token, + List? meals, TimeOfDay? wakeupController, TimeOfDay? retireController, TimeOfDay? mealTimeController, @@ -85,6 +92,8 @@ class DiaryEditLoadedState extends DiaryEditState { return DiaryEditLoadedState( diaryEditModelObj: diaryEditModelObj ?? this.diaryEditModelObj, diaryDate: diaryDate ?? this.diaryDate, + token: token ?? this.token, + meals: meals ?? this.meals, wakeupController: wakeupController ?? this.wakeupController, retireController: retireController ?? this.retireController, mealTimeController: mealTimeController ?? this.mealTimeController, 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 fffaa692..6c33eab4 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -93,6 +93,7 @@ class DiaryEditScreen extends StatelessWidget { /// Section Widget Widget _buildHeaderRow(BuildContext context, DiaryEditLoadedState state) { + final day = state.diaryId; return Container( margin: EdgeInsets.symmetric(horizontal: 16.h, vertical: 16.h), padding: EdgeInsets.symmetric( @@ -126,7 +127,7 @@ class DiaryEditScreen extends StatelessWidget { Align( alignment: Alignment.centerRight, child: Text( - "10 день", + "$day день", style: CustomTextStyles.titleMediumBlack, ), ), @@ -238,7 +239,7 @@ class DiaryEditScreen extends StatelessWidget { maxWidth: MediaQuery.of(context).size.width - 260, ), child: GestureDetector( - onTap: () => _selectTime(context, state), + onTap: () => _selectMealTime(context, state), child: AbsorbPointer( child: CustomTextFormField( hintText: state.mealTimeController @@ -780,22 +781,23 @@ class DiaryEditScreen extends StatelessWidget { children: [ SizedBox(height: 20.v), GestureDetector( - onTap: () => _selectTime(context, state), + onTap: () => _selectWakeupTime(context, state), child: AbsorbPointer( child: CustomTextFormField( - hintText: state.wakeupController + hintText: state.wakeupController + ?.format(context) + .toString(), + prefix: Icon(Icons.sunny), + autofocus: false, + /*initialValue: state.wakeupController ?.format(context) - .toString(), - prefix: Icon(Icons.sunny), - autofocus: false, - initialValue: state.wakeupController - ?.format(context) - .toString()), + .toString()*/ + ), ), ), SizedBox(height: 20.v), GestureDetector( - onTap: () => _selectTime(context, state), + onTap: () => _selectRetireTime(context, state), child: AbsorbPointer( child: CustomTextFormField( hintText: state.retireController @@ -803,9 +805,9 @@ class DiaryEditScreen extends StatelessWidget { .toString(), prefix: Icon(Icons.bed), autofocus: false, - initialValue: state.retireController + /*initialValue: state.retireController ?.format(context) - .toString(), + .toString(),*/ ), ), ), @@ -939,7 +941,7 @@ class DiaryEditScreen extends StatelessWidget { ]))); } - Future _selectTime( + Future _selectWakeupTime( BuildContext context, DiaryEditLoadedState state) async { final TimeOfDay? pickedTime = await showTimePicker( context: context, @@ -947,236 +949,40 @@ class DiaryEditScreen extends StatelessWidget { ); if (pickedTime != null && pickedTime != state.wakeupController) { state.wakeupController = pickedTime; - context.read().add(ChangeMealTime( + context.read().add(WakeupEvent( state.diaryId, pickedTime, )); } } -/*Widget _buildImageStack(BuildContext context) { - return Container( - padding: EdgeInsets.symmetric( - horizontal: 24.h, - vertical: 12.v, - ), - decoration: AppDecoration.outlinePrimary.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder12, - ), - child: Stack( - alignment: Alignment.bottomCenter, - children: [ - Align( - alignment: Alignment.center, - child: Container( - margin: EdgeInsets.symmetric(horizontal: 10.h), - padding: EdgeInsets.symmetric( - horizontal: 10.h, - vertical: 13.v, - ), - decoration: AppDecoration.outlinePrimary.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder12, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: EdgeInsets.symmetric(horizontal: 10.h), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Время приема пищи", - style: CustomTextStyles.bodyMediumBlack900, - ), - _buildMealTime(context), - ], - ), - ), - SizedBox(height: 20.v), - Padding( - padding: EdgeInsets.symmetric(horizontal: 10.h), - child: CustomDropDown( - hintText: "Прием пищи", - items: dropdownItemList1, - contentPadding: EdgeInsets.symmetric( - horizontal: 15.h, - vertical: 9.v, - ), - onChanged: (value) {}, - ), - ), - SizedBox(height: 20.v), - _buildEnterProductName(context), - SizedBox(height: 20.v), - Padding( - padding: EdgeInsets.symmetric(horizontal: 10.h), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - _buildQuantity(context), - Padding( - padding: EdgeInsets.only(left: 10.h), - child: CustomDropDown( - width: 146.h, - hintText: "Порция", - items: dropdownItemList2, - contentPadding: EdgeInsets.symmetric( - horizontal: 15.h, - vertical: 9.v, - ), - onChanged: (value) {}, - ), - ), - ], - ), - ), - SizedBox(height: 30.v), - Container( - margin: EdgeInsets.symmetric(horizontal: 10.h), - padding: EdgeInsets.symmetric( - horizontal: 8.h, - vertical: 6.v, - ), - decoration: AppDecoration.fillGray.copyWith( - borderRadius: BorderRadiusStyle.roundedBorder5, - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: EdgeInsets.only( - left: 7.h, - top: 5.v, - ), - child: Text( - "Сырный суп", - style: CustomTextStyles.titleMedium16, - ), - ), - Padding( - padding: EdgeInsets.only( - left: 20.h, - top: 3.v, - bottom: 3.v, - ), - child: Text( - "400мл", - style: CustomTextStyles.titleMedium16, - ), - ), - Spacer(), - CustomImageView( - imagePath: ImageConstant.imgSearch, - height: 24.adaptSize, - width: 24.adaptSize, - ), - CustomImageView( - imagePath: ImageConstant.imgClose, - height: 28.adaptSize, - width: 28.adaptSize, - margin: EdgeInsets.only(left: 10.h), - ), - ], - ), - ), - SizedBox(height: 30.v), - _buildAddProduct(context), - SizedBox(height: 249.v), - _buildAddPhoto(context), - SizedBox(height: 29.v), - Text( - "Ваша сытость после приёма пищи", - style: CustomTextStyles.bodyMediumBlack900, - ), - SizedBox(height: 15.v), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - CustomImageView( - imagePath: ImageConstant.imgEdit, - height: 30.adaptSize, - width: 30.adaptSize, - ), - CustomImageView( - height: 13.v, - width: 243.h, - margin: EdgeInsets.only( - left: 10.h, - top: 9.v, - bottom: 8.v, - ), - ), - CustomImageView( - height: 30.adaptSize, - width: 30.adaptSize, - margin: EdgeInsets.only(left: 10.h), - ), - ], - ), - SizedBox(height: 7.v), - ], - ), - ), - ), - Align( - alignment: Alignment.bottomCenter, - child: Container( - height: 203.v, - width: 303.h, - margin: EdgeInsets.only(bottom: 178.v), - child: Stack( - alignment: Alignment.topRight, - children: [ - CustomImageView( - height: 203.v, - width: 303.h, - radius: BorderRadius.circular( - 5.h, - ), - alignment: Alignment.center, - ), - Align( - alignment: Alignment.topRight, - child: Padding( - padding: EdgeInsets.only( - left: 265.h, - top: 10.v, - right: 10.h, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - CustomIconButton( - height: 18.adaptSize, - width: 18.adaptSize, - padding: EdgeInsets.all(4.h), - alignment: Alignment.centerRight, - child: CustomImageView( - imagePath: ImageConstant.imgCloseBlueGray900, - ), - ), - SizedBox(height: 60.v), - CustomIconButton( - height: 28.adaptSize, - width: 28.adaptSize, - padding: EdgeInsets.all(9.h), - decoration: IconButtonStyleHelper.fillBlueA, - child: CustomImageView( - imagePath: ImageConstant.imageNotFound, - ), - ), - ], - ), - ), - ), - ], - ), - ), - ), - ], - ), + Future _selectRetireTime( + BuildContext context, DiaryEditLoadedState state) async { + final TimeOfDay? pickedTime = await showTimePicker( + context: context, + initialTime: state.retireController ?? TimeOfDay.now(), ); - }*/ + if (pickedTime != null && pickedTime != state.retireController) { + state.retireController = pickedTime; + context.read().add(RetireEvent( + pickedTime, + state.diaryId, + )); + } + } + + Future _selectMealTime( + BuildContext context, DiaryEditLoadedState state) async { + final TimeOfDay? pickedTime = await showTimePicker( + context: context, + initialTime: state.mealTimeController ?? TimeOfDay.now(), + ); + if (pickedTime != null && pickedTime != state.mealTimeController) { + state.mealTimeController = pickedTime; + context.read().add(ChangeMealTime( + state.diaryId, + pickedTime, + )); + } + } } diff --git a/lib/presentation/diary/diary_edit_screen/models/diary_edit_model.dart b/lib/presentation/diary/diary_edit_screen/models/diary_edit_model.dart index 32afe5d1..a175b889 100644 --- a/lib/presentation/diary/diary_edit_screen/models/diary_edit_model.dart +++ b/lib/presentation/diary/diary_edit_screen/models/diary_edit_model.dart @@ -9,9 +9,11 @@ class DiaryEditModel extends Equatable { DiaryEditModel({this.mealList = const []}); List mealList; - DiaryEditModel copyWith() { + DiaryEditModel copyWith({ + List? mealList, + }) { return DiaryEditModel( - mealList: mealList, + mealList: mealList ?? this.mealList, ); } From becf515accd0ad420f9a82c9cd77b7aff2d6d9c4 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 21 Feb 2024 14:34:04 +0300 Subject: [PATCH 25/32] feat(diary) Dynamic current meal display --- .../diary_edit_screen/bloc/diary_edit_bloc.dart | 14 +++++++++++--- .../diary_edit_screen/bloc/diary_edit_event.dart | 8 +++----- .../diary/diary_edit_screen/diary_edit_screen.dart | 5 ++--- 3 files changed, 16 insertions(+), 11 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 2a912026..3c103e80 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 @@ -40,7 +40,7 @@ class DiaryEditBloc extends Bloc { ) async { try { final token = - "1|laravel_sanctum_8qeVUwDzs440SoG1pJFdSFtYWjJhZfEQXqStVkFPea8d4092"; + "laravel_sanctum_RzcUqh1zBYFCIG5tBFvfxyvA1NER9fMQiKlqlJFYeb618e64"; final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/index'), headers: { @@ -61,7 +61,7 @@ class DiaryEditBloc extends Bloc { ); final diary = jsonDecode(response.body)['diary']; if (diary is Map) { - print(diary); + print(diary['meals'][1].runtimeType); final String diaryDate = diary['date'] ?? DateTime.now().toString(); // Продолжайте обработку данных дневника @@ -69,6 +69,7 @@ class DiaryEditBloc extends Bloc { // Если текущее состояние уже загружено, обновляем его var currentState = state as DiaryEditLoadedState; emit((currentState).copyWith( + currentMeal: currentState.currentMeal, wakeupExpanded: currentState.wakeupExpanded, moodExpanded: currentState.moodExpanded, token: currentState.token, @@ -88,6 +89,8 @@ class DiaryEditBloc extends Bloc { } else { // Если текущее состояние - начальное, создаем новое загруженное состояние emit(DiaryEditLoadedState( + currentMeal: SelectionPopupModel( + id: 0, title: "Прием пищи 1", isSelected: true), wakeupExpanded: true, moodExpanded: true, token: token, @@ -229,7 +232,12 @@ class DiaryEditBloc extends Bloc { if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; - emit(currentState.copyWith(currentMeal: event.value)); + emit(currentState.copyWith( + currentMeal: event.value, + mealTimeController: + toTime(event.meals?[event.value.id ?? 0]['time'] ?? "09:00"), + selectedMood: event.meals?[event.value.id ?? 0]['mood'], + selectedSatiety: event.meals?[event.value.id ?? 0]['satiety'])); currentState.currentMeal = event.value; } } 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 ab16a29a..8f396765 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 @@ -110,12 +110,10 @@ class UploadImages extends DiaryEditEvent { } class ChangeMeal extends DiaryEditEvent { - ChangeMeal({required this.value}); + ChangeMeal({required this.value, required this.meals}); SelectionPopupModel value; - + List? meals; @override - List get props => [ - value, - ]; + List get props => [value, meals]; } 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 6c33eab4..87d08ed8 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -269,9 +269,8 @@ class DiaryEditScreen extends StatelessWidget { vertical: 9.v, ), onChanged: (value) { - context - .read() - .add(ChangeMeal(value: value)); + context.read().add( + ChangeMeal(meals: state.meals, value: value)); }, ); })), From 75f7d52d390e2f7167bcd9dba644e7203fb5fd1d Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 21 Feb 2024 15:29:10 +0300 Subject: [PATCH 26/32] feat(diary) Default Meal time values and Portions dynamic display for each meal --- .../diary_edit_screen/bloc/diary_edit_bloc.dart | 12 +++++++----- .../diary_edit_screen/bloc/diary_edit_state.dart | 5 +++++ .../diary/diary_edit_screen/diary_edit_screen.dart | 11 +++++++---- lib/widgets/custom_edit_drop_down.dart | 4 ++++ 4 files changed, 23 insertions(+), 9 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 3c103e80..1133d779 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 @@ -95,11 +95,13 @@ class DiaryEditBloc extends Bloc { moodExpanded: true, token: token, meals: diary['meals'], + portions: diary['meals'][0]['portions'], wakeupController: toTime(diary['wakeup'] ?? "09:00"), retireController: toTime(diary['retire'] ?? "23:00"), - mealTimeController: TimeOfDay.now(), - selectedSatiety: 3, - selectedMood: 3, + mealTimeController: + toTime(diary['meals'][0]['time'] ?? "10:00"), + selectedSatiety: diary['meals'][0]['satiety'], + selectedMood: diary['meals'][0]['mood'], commentController: TextEditingController(text: diary['comment']), productNameController: TextEditingController(), @@ -231,11 +233,11 @@ class DiaryEditBloc extends Bloc { FutureOr _changeMeal(ChangeMeal event, Emitter emit) { if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; - + int? id = event.value.id; emit(currentState.copyWith( currentMeal: event.value, mealTimeController: - toTime(event.meals?[event.value.id ?? 0]['time'] ?? "09:00"), + toTime(event.meals?[event.value.id ?? 0]['time'] ?? "1$id:00"), selectedMood: event.meals?[event.value.id ?? 0]['mood'], selectedSatiety: event.meals?[event.value.id ?? 0]['satiety'])); currentState.currentMeal = event.value; diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart index 6485475d..4ba46d61 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart @@ -23,6 +23,7 @@ class DiaryEditLoadedState extends DiaryEditState { this.diaryDate, this.token, this.meals, + this.portions, this.wakeupController, this.retireController, this.commentController, @@ -41,6 +42,7 @@ class DiaryEditLoadedState extends DiaryEditState { String? diaryDate; String? token; List? meals; + List? portions; SelectionPopupModel? currentMeal; TimeOfDay? wakeupController; TimeOfDay? retireController; @@ -58,6 +60,7 @@ class DiaryEditLoadedState extends DiaryEditState { diaryEditModelObj, diaryDate, token, + meals, wakeupController, retireController, mealTimeController, @@ -77,6 +80,7 @@ class DiaryEditLoadedState extends DiaryEditState { String? diaryDate, String? token, List? meals, + List? portions, TimeOfDay? wakeupController, TimeOfDay? retireController, TimeOfDay? mealTimeController, @@ -94,6 +98,7 @@ class DiaryEditLoadedState extends DiaryEditState { diaryDate: diaryDate ?? this.diaryDate, token: token ?? this.token, meals: meals ?? this.meals, + portions: portions ?? this.portions, wakeupController: wakeupController ?? this.wakeupController, retireController: retireController ?? this.retireController, mealTimeController: mealTimeController ?? this.mealTimeController, 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 87d08ed8..c1813419 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -268,6 +268,7 @@ class DiaryEditScreen extends StatelessWidget { horizontal: 10.h, vertical: 9.v, ), + defaultValue: diaryEditModelObj?.mealList[0], onChanged: (value) { context.read().add( ChangeMeal(meals: state.meals, value: value)); @@ -308,7 +309,9 @@ class DiaryEditScreen extends StatelessWidget { SizedBox(height: 30.v), _buildAddProduct(context), SizedBox(height: 30.v), - _buildProduct(context), + ...state.portions! + .map((portion) => _buildProduct(context, portion)) + .toList(), SizedBox(height: 30.v), _buildAddPhoto(context), SizedBox(height: 30.v), @@ -392,7 +395,7 @@ class DiaryEditScreen extends StatelessWidget { )); } - _buildProduct(BuildContext context) { + _buildProduct(BuildContext context, Map portion) { return Container( margin: EdgeInsets.symmetric(horizontal: 10.h), padding: EdgeInsets.symmetric( @@ -412,7 +415,7 @@ class DiaryEditScreen extends StatelessWidget { top: 5.v, ), child: Text( - "Сырный суп", + portion['name'], style: CustomTextStyles.titleMedium16, ), ), @@ -423,7 +426,7 @@ class DiaryEditScreen extends StatelessWidget { bottom: 3.v, ), child: Text( - "15гр", + portion['quantity'] + portion['portion'], ), ), Spacer(), diff --git a/lib/widgets/custom_edit_drop_down.dart b/lib/widgets/custom_edit_drop_down.dart index 67a2a1f9..59c58593 100644 --- a/lib/widgets/custom_edit_drop_down.dart +++ b/lib/widgets/custom_edit_drop_down.dart @@ -23,6 +23,7 @@ class CustomDropDown extends StatelessWidget { this.filled = true, this.validator, this.onChanged, + this.defaultValue, }) : super( key: key, ); @@ -61,6 +62,8 @@ class CustomDropDown extends StatelessWidget { final bool? filled; + final SelectionPopupModel? defaultValue; + final FormFieldValidator? validator; final Function(SelectionPopupModel)? onChanged; @@ -94,6 +97,7 @@ class CustomDropDown extends StatelessWidget { }).toList(), decoration: decoration, validator: validator, + value: defaultValue, onChanged: (value) { onChanged!(value!); }, From 05e04c444fbf435038ca69c5a56766c647f33233 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 21 Feb 2024 15:29:37 +0300 Subject: [PATCH 27/32] fix(diary) Fix --- .../diary/diary_edit_screen/bloc/diary_edit_bloc.dart | 1 + 1 file changed, 1 insertion(+) 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 1133d779..1d70efee 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 @@ -236,6 +236,7 @@ class DiaryEditBloc extends Bloc { int? id = event.value.id; emit(currentState.copyWith( currentMeal: event.value, + portions: event.meals?[event.value.id ?? 0]['portions'], mealTimeController: toTime(event.meals?[event.value.id ?? 0]['time'] ?? "1$id:00"), selectedMood: event.meals?[event.value.id ?? 0]['mood'], From 77bc29c3d5560f3db60d4829f18b6619ee86a77f Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 21 Feb 2024 20:19:15 +0300 Subject: [PATCH 28/32] feat(diary) Added network methods and routes --- .../bloc/diary_edit_bloc.dart | 331 ++++++++++++++---- .../bloc/diary_edit_event.dart | 30 +- .../diary_edit_screen/diary_edit_screen.dart | 81 ++--- .../my_profile_screen/my_profile_screen.dart | 2 - 4 files changed, 309 insertions(+), 135 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 1d70efee..951c7ae6 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 @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:ffi'; import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; @@ -8,7 +7,6 @@ import 'package:image_picker/image_picker.dart'; import 'package:eatvio_app/presentation/diary/diary_edit_screen/models/diary_edit_model.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; -import 'package:hive/hive.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; part 'diary_edit_event.dart'; @@ -40,7 +38,7 @@ class DiaryEditBloc extends Bloc { ) async { try { final token = - "laravel_sanctum_RzcUqh1zBYFCIG5tBFvfxyvA1NER9fMQiKlqlJFYeb618e64"; + "laravel_sanctum_Q22zOtJhQUcJnh0kseZFblFv5XAPaKbG3gTM5hga71ecbb49"; final response = await http.get( Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/index'), headers: { @@ -145,10 +143,44 @@ class DiaryEditBloc extends Bloc { emit(updatedState); // Передаем обновленное состояние в emit - currentState.selectedSatiety = event.selectedElement; + // Отправляем данные по HTTP маршруту и ждем ответ + var response = await sendSatietyData( + currentState.token, + event.selectedElement, + currentState.currentMeal?.id, + currentState.diaryId); + + if (response.statusCode == 200) { + currentState.selectedSatiety = event.selectedElement; + emit(currentState); // Передаем обновленное состояние в emit + } } } + Future sendSatietyData( + String? token, + int selectedSatiety, + int? mealID, + int diaryID, + ) async { + String url = + dotenv.env['SERVER_ROOT']! + '$diaryID/meal/$mealID/satiety/fill'; + final credentials = { + 'satiety': selectedSatiety, + 'meal_id': mealID, + 'diary_id': diaryID, + }; + + var response = await http.post(Uri.parse(url), + headers: { + 'Authorization': 'Bearer $token', + }, + body: json.encode(credentials), + encoding: utf8); + + return response; + } + Future _changeMood( ChangeMood event, Emitter emit) async { if (state is DiaryEditLoadedState) { @@ -158,8 +190,180 @@ class DiaryEditBloc extends Bloc { emit(updatedState); // Передаем обновленное состояние в emit - currentState.selectedMood = event.selectedElement; - print(currentState.mealTimeController); + // Отправляем данные по HTTP маршруту и ждем ответ + var response = await sendMoodData( + currentState.token, + event.selectedElement, + currentState.currentMeal?.id, + currentState.diaryId); + + if (response.statusCode == 200) { + currentState.selectedMood = event.selectedElement; + emit(currentState); // Передаем обновленное состояние в emit + } + } + } + + Future sendMoodData( + String? token, + int selectedMood, + int? mealID, + int diaryID, + ) async { + String url = + dotenv.env['SERVER_ROOT']! + '/$diaryID/meal/$mealID/mood/fill'; + final credentials = { + 'mood': selectedMood, + 'meal_id': mealID, + 'diary_id': diaryID, + }; + + var response = await http.post(Uri.parse(url), + headers: { + 'Authorization': 'Bearer $token', + }, + body: json.encode(credentials), + encoding: utf8); + + return response; + } + + FutureOr _changeWakeup( + WakeupEvent event, Emitter emit) async { + if (state is DiaryEditLoadedState) { + var currentState = state as DiaryEditLoadedState; + var updatedState = + currentState.copyWith(wakeupController: event.selectedTime); + + emit(updatedState); // Передаем обновленное состояние в emit + + // Отправляем данные по HTTP маршруту и ждем ответ + var response = await sendWakeupData( + currentState.token, event.selectedTime, currentState.diaryId); + + if (response.statusCode == 200) { + currentState.wakeupController = event.selectedTime; + emit(currentState); // Передаем обновленное состояние в emit + } + } + } + + Future sendWakeupData( + String? token, + TimeOfDay wakeup, + int diaryID, + ) async { + String url = dotenv.env['SERVER_ROOT']! + '/diary/???'; + final credentials = { + 'wakeup': wakeup, + 'diary_id': diaryID, + }; + + var response = await http.post(Uri.parse(url), + headers: { + 'Authorization': 'Bearer $token', + }, + body: json.encode(credentials), + encoding: utf8); + + return response; + } + + FutureOr _changeRetire( + RetireEvent event, Emitter emit) async { + if (state is DiaryEditLoadedState) { + var currentState = state as DiaryEditLoadedState; + var updatedState = + currentState.copyWith(retireController: event.selectedTime); + + emit(updatedState); // Передаем обновленное состояние в emit + + // Отправляем данные по HTTP маршруту и ждем ответ + var response = await sendRetireData( + currentState.token, event.selectedTime, currentState.diaryId); + + if (response.statusCode == 200) { + currentState.retireController = event.selectedTime; + emit(currentState); // Передаем обновленное состояние в emit + } + } + } + + Future sendRetireData( + String? token, + TimeOfDay retire, + int diaryID, + ) async { + String url = dotenv.env['SERVER_ROOT']! + '/diary/???'; + final credentials = { + 'wakeup': retire, + 'diary_id': diaryID, + }; + + var response = await http.post(Uri.parse(url), + headers: { + 'Authorization': 'Bearer $token', + }, + body: json.encode(credentials), + encoding: utf8); + + return response; + } + + FutureOr _changeMealTime( + ChangeMealTime event, Emitter emit) async { + if (state is DiaryEditLoadedState) { + var currentState = state as DiaryEditLoadedState; + var updatedState = currentState.copyWith(mealTimeController: event.time); + + emit(updatedState); // Передаем обновленное состояние в emit + + // Отправляем данные по HTTP маршруту и ждем ответ + var response = await sendMealTimeData(currentState.token, event.time, + currentState.currentMeal?.id, currentState.diaryId); + + if (response.statusCode == 200) { + currentState.retireController = event.time; + emit(currentState); // Передаем обновленное состояние в emit + } + } + } + + Future sendMealTimeData( + String? token, + TimeOfDay mealTime, + int? mealID, + int diaryID, + ) async { + String url = dotenv.env['SERVER_ROOT']! + '/diary/???'; + final credentials = { + 'time': mealTime, + 'meal_id': mealID, + 'diary_id': diaryID, + }; + + var response = await http.post(Uri.parse(url), + headers: { + 'Authorization': 'Bearer $token', + }, + body: json.encode(credentials), + encoding: utf8); + + return response; + } + + FutureOr _changeMeal(ChangeMeal event, Emitter emit) { + if (state is DiaryEditLoadedState) { + var currentState = state as DiaryEditLoadedState; + int? id = event.value.id; + emit(currentState.copyWith( + currentMeal: event.value, + portions: event.meals?[event.value.id ?? 0]['portions'], + mealTimeController: + toTime(event.meals?[event.value.id ?? 0]['time'] ?? "1$id:00"), + selectedMood: event.meals?[event.value.id ?? 0]['mood'], + selectedSatiety: event.meals?[event.value.id ?? 0]['satiety'])); + currentState.currentMeal = event.value; } } @@ -183,69 +387,74 @@ class DiaryEditBloc extends Bloc { } } - FutureOr _changeWakeup( - WakeupEvent event, Emitter emit) { - if (state is DiaryEditLoadedState) { - var currentState = state as DiaryEditLoadedState; - - emit(currentState.copyWith(wakeupController: event.selectedTime)); - currentState.wakeupController = event.selectedTime; - print(currentState.wakeupController); - } - } - - FutureOr _changeRetire( - RetireEvent event, Emitter emit) { - if (state is DiaryEditLoadedState) { - var currentState = state as DiaryEditLoadedState; - - emit(currentState.copyWith(retireController: event.selectedTime)); - currentState.retireController = event.selectedTime; - print(currentState.retireController); - } - } - FutureOr _addPortion( - AddPortionEvent event, Emitter emit) {} - - FutureOr _removePortion( - RemovePortionEvent event, Emitter emit) {} - - Future> _uploadImages( - UploadImages event, Emitter emit) async { - String imageUrl = await uploadImageToServer(event.image.path); - print(imageUrl); - } - - FutureOr _addComment(AddComment event, Emitter emit) {} - - FutureOr _changeMealTime( - ChangeMealTime event, Emitter emit) { + AddPortionEvent event, Emitter emit) async { if (state is DiaryEditLoadedState) { var currentState = state as DiaryEditLoadedState; - - emit(currentState.copyWith(mealTimeController: event.time)); - currentState.mealTimeController = event.time; - print(currentState.mealTimeController); - } - } - - FutureOr _changeMeal(ChangeMeal event, Emitter emit) { - if (state is DiaryEditLoadedState) { - var currentState = state as DiaryEditLoadedState; - int? id = event.value.id; - emit(currentState.copyWith( - currentMeal: event.value, - portions: event.meals?[event.value.id ?? 0]['portions'], + int? id = currentState.currentMeal?.id; + var updatedState = currentState.copyWith( + currentMeal: currentState.diaryEditModelObj?.mealList[id ?? 0], + portions: currentState.meals?[id ?? 0]['portions'], mealTimeController: - toTime(event.meals?[event.value.id ?? 0]['time'] ?? "1$id:00"), - selectedMood: event.meals?[event.value.id ?? 0]['mood'], - selectedSatiety: event.meals?[event.value.id ?? 0]['satiety'])); - currentState.currentMeal = event.value; + toTime(currentState.meals?[id ?? 0]['time'] ?? "1$id:00"), + selectedMood: currentState.meals?[id ?? 0]['mood'], + selectedSatiety: currentState.meals?[id ?? 0]['satiety']); + emit(updatedState); // Передаем обновленное состояние в emit + + // Отправляем данные по HTTP маршруту и ждем ответ + var response = await sendPortionData( + currentState.token, + event.name, + event.portion, + event.quantity, + currentState.currentMeal!.id, + currentState.diaryId); + + if (response.statusCode == 200) { + emit(currentState); // Передаем обновленное состояние в emit + } } } + + Future sendPortionData( + String? token, + String name, + String portion, + int quantity, + int? mealID, + int diaryID, + ) async { + String url = + dotenv.env['SERVER_ROOT']! + '/$diaryID/meal/$mealID/portions/create'; + final credentials = { + 'name': name, + 'portion': portion, + 'quantity': quantity, + 'meal_id': mealID, + 'diary_id': diaryID, + }; + + var response = await http.post(Uri.parse(url), + headers: { + 'Authorization': 'Bearer $token', + }, + body: json.encode(credentials), + encoding: utf8); + + return response; + } } +FutureOr _removePortion( + RemovePortionEvent event, Emitter emit) {} + +Future> _uploadImages( + UploadImages event, Emitter emit) async { + String imageUrl = await uploadImageToServer(event.image.path); + print(imageUrl); +} + +FutureOr _addComment(AddComment event, Emitter emit) {} Future uploadImageToServer(String imagePath) async { var request = http.MultipartRequest( 'POST', 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 8f396765..236ecbcd 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 @@ -18,34 +18,29 @@ class DiaryEditInitialEvent extends DiaryEditEvent { class ChangeSatiety extends DiaryEditEvent { ChangeSatiety( this.selectedElement, - this.mealId, ); final int selectedElement; - final int mealId; @override - List get props => [selectedElement, mealId]; + List get props => [selectedElement]; } class ChangeMood extends DiaryEditEvent { ChangeMood( this.selectedElement, - this.diaryId, ); final int selectedElement; - final int diaryId; @override - List get props => [selectedElement, diaryId]; + List get props => [selectedElement]; } class ChangeMealTime extends DiaryEditEvent { - ChangeMealTime(this.mealId, this.time); - final int mealId; + ChangeMealTime(this.time); final TimeOfDay time; @override - List get props => [mealId, time]; + List get props => [time]; } class AddComment extends DiaryEditEvent { @@ -58,21 +53,19 @@ class AddComment extends DiaryEditEvent { } class WakeupEvent extends DiaryEditEvent { - WakeupEvent(this.diaryId, this.selectedTime); + WakeupEvent(this.selectedTime); final TimeOfDay selectedTime; - final int diaryId; @override - List get props => [selectedTime, diaryId]; + List get props => [selectedTime]; } class RetireEvent extends DiaryEditEvent { - RetireEvent(this.selectedTime, this.diaryId); + RetireEvent(this.selectedTime); final TimeOfDay selectedTime; - final int diaryId; @override - List get props => [selectedTime, diaryId]; + List get props => [selectedTime]; } class ToggleMoodExpandedEvent extends DiaryEditEvent { @@ -86,13 +79,12 @@ class ToggleWakeupExpandedEvent extends DiaryEditEvent { } class AddPortionEvent extends DiaryEditEvent { - AddPortionEvent(this.mealId, this.productId, this.quantity, this.portion); - final int mealId; - final int productId; + AddPortionEvent(this.name, this.quantity, this.portion); + final String name; final int quantity; final String portion; @override - List get props => [mealId, productId, quantity, portion]; + List get props => [name, quantity, portion]; } class RemovePortionEvent extends DiaryEditEvent { 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 c1813419..04206dd4 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -331,54 +331,42 @@ class DiaryEditScreen extends StatelessWidget { color: Colors.red, isSelected: state.selectedSatiety == 0, onTap: () { - context - .read() - .add(ChangeSatiety(0, state.diaryId)); + context.read().add(ChangeSatiety(0)); }, ), ScaleElement( color: Colors.orange, isSelected: state.selectedSatiety == 1, onTap: () { - context - .read() - .add(ChangeSatiety(1, state.diaryId)); + context.read().add(ChangeSatiety(1)); }, ), ScaleElement( color: Colors.yellow, isSelected: state.selectedSatiety == 2, onTap: () { - context - .read() - .add(ChangeSatiety(2, state.diaryId)); + context.read().add(ChangeSatiety(2)); }, ), ScaleElement( color: Colors.lime, isSelected: state.selectedSatiety == 3, onTap: () { - context - .read() - .add(ChangeSatiety(3, state.diaryId)); + context.read().add(ChangeSatiety(3)); }, ), ScaleElement( color: Colors.lightGreen, isSelected: state.selectedSatiety == 4, onTap: () { - context - .read() - .add(ChangeSatiety(4, state.diaryId)); + context.read().add(ChangeSatiety(4)); }, ), ScaleElement( color: Colors.green, isSelected: state.selectedSatiety == 5, onTap: () { - context - .read() - .add(ChangeSatiety(5, state.diaryId)); + context.read().add(ChangeSatiety(5)); }, ), Text("😊"), @@ -415,7 +403,7 @@ class DiaryEditScreen extends StatelessWidget { top: 5.v, ), child: Text( - portion['name'], + portion['product_name'], style: CustomTextStyles.titleMedium16, ), ), @@ -430,13 +418,19 @@ class DiaryEditScreen extends StatelessWidget { ), ), Spacer(), - Padding( - padding: const EdgeInsets.only(right: 10), - child: Icon( - Icons.close, - color: appTheme.blueGray300, - ), - ) + GestureDetector( + onTap: () { + context + .read() + .add(RemovePortionEvent(portion['id'])); + }, + child: Padding( + padding: const EdgeInsets.only(right: 10), + child: Icon( + Icons.close, + color: appTheme.blueGray300, + ), + )), ], ), ); @@ -886,54 +880,42 @@ class DiaryEditScreen extends StatelessWidget { color: Colors.red, isSelected: state.selectedMood == 0, onTap: () { - context - .read() - .add(ChangeMood(0, state.diaryId)); + context.read().add(ChangeMood(0)); }, ), ScaleElement( color: Colors.orange, isSelected: state.selectedMood == 1, onTap: () { - context - .read() - .add(ChangeMood(1, state.diaryId)); + context.read().add(ChangeMood(1)); }, ), ScaleElement( color: Colors.yellow, isSelected: state.selectedMood == 2, onTap: () { - context - .read() - .add(ChangeMood(2, state.diaryId)); + context.read().add(ChangeMood(2)); }, ), ScaleElement( color: Colors.lime, isSelected: state.selectedMood == 3, onTap: () { - context - .read() - .add(ChangeMood(3, state.diaryId)); + context.read().add(ChangeMood(3)); }, ), ScaleElement( color: Colors.lightGreen, isSelected: state.selectedMood == 4, onTap: () { - context - .read() - .add(ChangeMood(4, state.diaryId)); + context.read().add(ChangeMood(4)); }, ), ScaleElement( color: Colors.green, isSelected: state.selectedMood == 5, onTap: () { - context - .read() - .add(ChangeMood(5, state.diaryId)); + context.read().add(ChangeMood(5)); }, ), Text("😊"), @@ -952,7 +934,6 @@ class DiaryEditScreen extends StatelessWidget { if (pickedTime != null && pickedTime != state.wakeupController) { state.wakeupController = pickedTime; context.read().add(WakeupEvent( - state.diaryId, pickedTime, )); } @@ -966,10 +947,7 @@ class DiaryEditScreen extends StatelessWidget { ); if (pickedTime != null && pickedTime != state.retireController) { state.retireController = pickedTime; - context.read().add(RetireEvent( - pickedTime, - state.diaryId, - )); + context.read().add(RetireEvent(pickedTime)); } } @@ -981,10 +959,7 @@ class DiaryEditScreen extends StatelessWidget { ); if (pickedTime != null && pickedTime != state.mealTimeController) { state.mealTimeController = pickedTime; - context.read().add(ChangeMealTime( - state.diaryId, - pickedTime, - )); + context.read().add(ChangeMealTime(pickedTime)); } } } diff --git a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart index 3b65469e..3fe87cf2 100644 --- a/lib/presentation/profile/my_profile_screen/my_profile_screen.dart +++ b/lib/presentation/profile/my_profile_screen/my_profile_screen.dart @@ -1,5 +1,3 @@ -import 'dart:ffi'; - import 'bloc/my_profile_bloc.dart'; import 'models/my_profile_model.dart'; import 'package:eatvio_app/core/app_export.dart'; From c0bffe5ae2308974cd942d3a2c57755400b54663 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Mon, 26 Feb 2024 15:24:02 +0300 Subject: [PATCH 29/32] feat(diary): Mood and satiety finished --- .../bloc/diary_edit_bloc.dart | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 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 951c7ae6..9cfda07f 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 @@ -188,8 +188,6 @@ class DiaryEditBloc extends Bloc { var updatedState = currentState.copyWith(selectedMood: event.selectedElement); - emit(updatedState); // Передаем обновленное состояние в emit - // Отправляем данные по HTTP маршруту и ждем ответ var response = await sendMoodData( currentState.token, @@ -198,8 +196,8 @@ class DiaryEditBloc extends Bloc { currentState.diaryId); if (response.statusCode == 200) { - currentState.selectedMood = event.selectedElement; - emit(currentState); // Передаем обновленное состояние в emit + updatedState.selectedMood = event.selectedElement; + emit(updatedState); // Передаем обновленное состояние в emit } } } @@ -235,15 +233,13 @@ class DiaryEditBloc extends Bloc { var updatedState = currentState.copyWith(wakeupController: event.selectedTime); - emit(updatedState); // Передаем обновленное состояние в emit - // Отправляем данные по HTTP маршруту и ждем ответ var response = await sendWakeupData( currentState.token, event.selectedTime, currentState.diaryId); if (response.statusCode == 200) { - currentState.wakeupController = event.selectedTime; - emit(currentState); // Передаем обновленное состояние в emit + updatedState.wakeupController = event.selectedTime; + emit(updatedState); // Передаем обновленное состояние в emit } } } @@ -276,28 +272,22 @@ class DiaryEditBloc extends Bloc { var updatedState = currentState.copyWith(retireController: event.selectedTime); - emit(updatedState); // Передаем обновленное состояние в emit - // Отправляем данные по HTTP маршруту и ждем ответ var response = await sendRetireData( currentState.token, event.selectedTime, currentState.diaryId); if (response.statusCode == 200) { - currentState.retireController = event.selectedTime; - emit(currentState); // Передаем обновленное состояние в emit + updatedState.retireController = event.selectedTime; + emit(updatedState); // Передаем обновленное состояние в emit } } } Future sendRetireData( - String? token, - TimeOfDay retire, - int diaryID, - ) async { - String url = dotenv.env['SERVER_ROOT']! + '/diary/???'; + String? token, TimeOfDay retire, int diaryID, int? mealID) async { + String url = dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/retire/fill'; final credentials = { - 'wakeup': retire, - 'diary_id': diaryID, + 'retire': retire, }; var response = await http.post(Uri.parse(url), From c072d46deed914f0c2528bdadb5434320d3de2f8 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Tue, 27 Feb 2024 16:10:11 +0300 Subject: [PATCH 30/32] Autocomplete product names --- .../bloc/diary_edit_bloc.dart | 119 +++++++++++------- .../bloc/diary_edit_event.dart | 7 ++ .../bloc/diary_edit_state.dart | 5 + .../diary_edit_screen/diary_edit_screen.dart | 6 +- lib/widgets/custom_edit_text_form_field.dart | 4 + pubspec.yaml | 1 + 6 files changed, 99 insertions(+), 43 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 9cfda07f..1796418f 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 @@ -30,6 +30,8 @@ class DiaryEditBloc extends Bloc { _removePortion); // пользователь нажимает на крестик около продукта on(_uploadImages); //пользователь нажимает "Добавить фото" on(_addComment); //пользователь нажимает "Добавить комментарий" + on( + _inputProduct); //пользователь нажимает "Добавить комментарий" } Future _onInitialize( @@ -83,6 +85,7 @@ class DiaryEditBloc extends Bloc { diaryId: currentState.diaryId, productQuantityController: currentState.productQuantityController, + autocompleteList: currentState.autocompleteList, diaryEditModelObj: currentState.diaryEditModelObj)); } else { // Если текущее состояние - начальное, создаем новое загруженное состояние @@ -106,6 +109,7 @@ class DiaryEditBloc extends Bloc { productQuantityController: TextEditingController(), diaryId: diaryId, diaryDate: diaryDate, + autocompleteList: [], diaryEditModelObj: state.diaryEditModelObj ?.copyWith(mealList: fillMealList()))); } @@ -284,7 +288,7 @@ class DiaryEditBloc extends Bloc { } Future sendRetireData( - String? token, TimeOfDay retire, int diaryID, int? mealID) async { + String? token, TimeOfDay retire, int diaryID) async { String url = dotenv.env['SERVER_ROOT']! + '/diary/$diaryID/retire/fill'; final credentials = { 'retire': retire, @@ -433,51 +437,82 @@ class DiaryEditBloc extends Bloc { return response; } -} -FutureOr _removePortion( - RemovePortionEvent event, Emitter emit) {} + FutureOr _inputProduct( + ProductInput event, Emitter emit) async { + if (state is DiaryEditLoadedState) { + var currentState = state as DiaryEditLoadedState; + String? token = currentState.token; + final credentials = { + 'name': event.input, + }; + final uri = Uri.parse(dotenv.env['SERVER_ROOT']! + + '/diary/product_nutritional_values/filter?' + + Uri(queryParameters: credentials).query); + final response = await http.get( + uri, + headers: { + 'Authorization': 'Bearer $token', + }, + ); + final productNutritionalValues = + jsonDecode(response.body)['productNutritionalValue']; + if (productNutritionalValues is Map) { + var updatedState = currentState.copyWith( + autocompleteList: productNutritionalValues.values + .map((value) => value['name']) + .toList()); -Future> _uploadImages( - UploadImages event, Emitter emit) async { - String imageUrl = await uploadImageToServer(event.image.path); - print(imageUrl); -} + emit(updatedState); + } + } + } -FutureOr _addComment(AddComment event, Emitter emit) {} -Future uploadImageToServer(String imagePath) async { - var request = http.MultipartRequest( - 'POST', - Uri.parse('http://your-api-url.com/upload'), // Замените на ваш маршрут API - ); + FutureOr _removePortion( + RemovePortionEvent event, Emitter emit) {} - request.files.add(await http.MultipartFile.fromPath('image', imagePath)); + Future> _uploadImages( + UploadImages event, Emitter emit) async { + String imageUrl = await uploadImageToServer(event.image.path); + print(imageUrl); + } - var response = await request.send(); - if (response.statusCode == 200) { - var responseData = await response.stream.bytesToString(); - return responseData; - } else { - throw Exception('Ошибка при загрузке изображения'); + FutureOr _addComment(AddComment event, Emitter emit) {} + Future uploadImageToServer(String imagePath) async { + var request = http.MultipartRequest( + 'POST', + Uri.parse( + 'http://your-api-url.com/upload'), // Замените на ваш маршрут API + ); + + request.files.add(await http.MultipartFile.fromPath('image', imagePath)); + + var response = await request.send(); + if (response.statusCode == 200) { + var responseData = await response.stream.bytesToString(); + return responseData; + } else { + throw Exception('Ошибка при загрузке изображения'); + } + } + + TimeOfDay toTime(String timeStr) { + List timeParts = timeStr.split(":"); + int hour = int.parse(timeParts[0]); + int minute = int.parse(timeParts[1]); + + TimeOfDay timeOfDay = TimeOfDay(hour: hour, minute: minute); + return timeOfDay; + } + + List fillMealList() { + return [ + SelectionPopupModel(id: 0, title: "Прием пищи 1", isSelected: true), + SelectionPopupModel(id: 1, title: "Прием пищи 2"), + SelectionPopupModel(id: 2, title: "Прием пищи 3"), + SelectionPopupModel(id: 3, title: "Прием пищи 4"), + SelectionPopupModel(id: 4, title: "Прием пищи 5"), + SelectionPopupModel(id: 5, title: "Прием пищи 6"), + ]; } } - -TimeOfDay toTime(String timeStr) { - List timeParts = timeStr.split(":"); - int hour = int.parse(timeParts[0]); - int minute = int.parse(timeParts[1]); - - TimeOfDay timeOfDay = TimeOfDay(hour: hour, minute: minute); - return timeOfDay; -} - -List fillMealList() { - return [ - SelectionPopupModel(id: 0, title: "Прием пищи 1", isSelected: true), - SelectionPopupModel(id: 1, title: "Прием пищи 2"), - SelectionPopupModel(id: 2, title: "Прием пищи 3"), - SelectionPopupModel(id: 3, title: "Прием пищи 4"), - SelectionPopupModel(id: 4, title: "Прием пищи 5"), - SelectionPopupModel(id: 5, title: "Прием пищи 6"), - ]; -} 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 236ecbcd..206e5957 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 @@ -101,6 +101,13 @@ class UploadImages extends DiaryEditEvent { List get props => [image]; } +class ProductInput extends DiaryEditEvent { + ProductInput(this.input); + final String input; + @override + List get props => [input]; +} + class ChangeMeal extends DiaryEditEvent { ChangeMeal({required this.value, required this.meals}); diff --git a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart index 4ba46d61..c518e9af 100644 --- a/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart +++ b/lib/presentation/diary/diary_edit_screen/bloc/diary_edit_state.dart @@ -24,6 +24,7 @@ class DiaryEditLoadedState extends DiaryEditState { this.token, this.meals, this.portions, + this.autocompleteList, this.wakeupController, this.retireController, this.commentController, @@ -43,6 +44,7 @@ class DiaryEditLoadedState extends DiaryEditState { String? token; List? meals; List? portions; + List? autocompleteList; SelectionPopupModel? currentMeal; TimeOfDay? wakeupController; TimeOfDay? retireController; @@ -61,6 +63,7 @@ class DiaryEditLoadedState extends DiaryEditState { diaryDate, token, meals, + autocompleteList, wakeupController, retireController, mealTimeController, @@ -81,6 +84,7 @@ class DiaryEditLoadedState extends DiaryEditState { String? token, List? meals, List? portions, + List? autocompleteList, TimeOfDay? wakeupController, TimeOfDay? retireController, TimeOfDay? mealTimeController, @@ -98,6 +102,7 @@ class DiaryEditLoadedState extends DiaryEditState { diaryDate: diaryDate ?? this.diaryDate, token: token ?? this.token, meals: meals ?? this.meals, + autocompleteList: autocompleteList ?? this.autocompleteList, portions: portions ?? this.portions, wakeupController: wakeupController ?? this.wakeupController, retireController: retireController ?? this.retireController, 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 04206dd4..2bc07d97 100644 --- a/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart +++ b/lib/presentation/diary/diary_edit_screen/diary_edit_screen.dart @@ -70,7 +70,6 @@ class DiaryEditScreen extends StatelessWidget { SizedBox(height: 30.v), _buildWakupRetire(context, state), SizedBox(height: 30.v), - //_buildImageStack(context), _buildMeal(context, state), SizedBox(height: 20.v), _buildMood(context, state), @@ -281,6 +280,11 @@ class DiaryEditScreen extends StatelessWidget { child: CustomTextFormField( hintText: "Введите названия продукта", controller: state.productNameController, + onChanged: (value) { + if (value.length > 3) { + context.read().add(ProductInput(value)); + } + }, ), ), SizedBox(height: 20.v), diff --git a/lib/widgets/custom_edit_text_form_field.dart b/lib/widgets/custom_edit_text_form_field.dart index 5a5687fb..5b27a43f 100644 --- a/lib/widgets/custom_edit_text_form_field.dart +++ b/lib/widgets/custom_edit_text_form_field.dart @@ -29,6 +29,7 @@ class CustomTextFormField extends StatelessWidget { this.filled = true, this.validator, this.keyboardType, + this.onChanged, this.onSaved, }) : super( key: key, @@ -84,6 +85,8 @@ class CustomTextFormField extends StatelessWidget { final void Function(String?)? onSaved; + final ValueChanged? onChanged; + @override Widget build(BuildContext context) { return alignment != null @@ -108,6 +111,7 @@ class CustomTextFormField extends StatelessWidget { validator: validator, keyboardType: keyboardType, onSaved: onSaved, + onChanged: onChanged, inputFormatters: inputFormatters, initialValue: initialValue, ), diff --git a/pubspec.yaml b/pubspec.yaml index 711ce10f..ac6ac205 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -25,6 +25,7 @@ dependencies: carousel_slider: ^4.2.1 flutter_form_builder: ^9.2.1 image_picker: ^1.0.7 + flutter_typeahead: ^5.2.0 dev_dependencies: flutter_test: From 8f3244f6079aab92a064fc4e15e55a742a7f7f28 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 28 Feb 2024 11:08:57 +0300 Subject: [PATCH 31/32] refactor(diary): Usnused imports and deprecated metods removed --- lib/widgets/custom_bottom_bar.dart | 1 + lib/widgets/custom_image_view.dart | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/widgets/custom_bottom_bar.dart b/lib/widgets/custom_bottom_bar.dart index 67ae4e3f..c32781a2 100644 --- a/lib/widgets/custom_bottom_bar.dart +++ b/lib/widgets/custom_bottom_bar.dart @@ -1,6 +1,7 @@ import 'package:eatvio_app/core/app_export.dart'; import 'package:flutter/material.dart'; +// ignore: must_be_immutable class CustomBottomBar extends StatefulWidget { CustomBottomBar({this.onChanged}); diff --git a/lib/widgets/custom_image_view.dart b/lib/widgets/custom_image_view.dart index 5bed7a28..03bd0cbf 100644 --- a/lib/widgets/custom_image_view.dart +++ b/lib/widgets/custom_image_view.dart @@ -96,7 +96,6 @@ class CustomImageView extends StatelessWidget { height: height, width: width, fit: fit ?? BoxFit.contain, - color: color, ), ); case ImageType.file: From b389a2a13feb5430cf7b61bca47251e255646e17 Mon Sep 17 00:00:00 2001 From: maxxkim Date: Wed, 28 Feb 2024 11:57:23 +0300 Subject: [PATCH 32/32] refactor(test): Flutter Analyze fix --- .env.example | 2 ++ lib/core/utils/size_utils.dart | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..98d26074 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +SERVER_ROOT='https://ohngeeri3ien-dev3.eatvio.ru/api' +STORAGE_URL='https://ohngeeri3ien-dev3.eatvio.ru/storage/' \ No newline at end of file diff --git a/lib/core/utils/size_utils.dart b/lib/core/utils/size_utils.dart index ddc30061..8911620b 100644 --- a/lib/core/utils/size_utils.dart +++ b/lib/core/utils/size_utils.dart @@ -3,7 +3,8 @@ import 'package:flutter/material.dart'; // This functions are responsible to make UI responsive across all the mobile devices. -MediaQueryData mediaQueryData = MediaQueryData.fromWindow(ui.window); +// ignore: deprecated_member_use +MediaQueryData mediaQueryData = MediaQueryData.fromView(ui.window); // These are the Viewport values of your Figma Design. // These are used in the code as a reference to create your UI Responsively.