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; - }); - } - } -}