forked from eatvio/eatvio_app
refactor(diary) Added more layouts and constrollers
This commit is contained in:
@@ -68,6 +68,14 @@ class AuthScreen extends StatelessWidget {
|
|||||||
Navigator.pushNamed(
|
Navigator.pushNamed(
|
||||||
context, AppRoutes.languageSelectScreen);
|
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<AuthBloc, AuthState>(builder: (context, state) {
|
BlocBuilder<AuthBloc, AuthState>(builder: (context, state) {
|
||||||
return NextStepButton(
|
return NextStepButton(
|
||||||
text: "authentificate".tr.toUpperCase(),
|
text: "authentificate".tr.toUpperCase(),
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
|||||||
Emitter<DiaryEditState> emit,
|
Emitter<DiaryEditState> emit,
|
||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
final box = await Hive.openBox('token');
|
/*final box = await Hive.openBox('token');
|
||||||
final token = box.get('token');
|
final token = box.get('token');*/
|
||||||
|
final token =
|
||||||
|
"1|laravel_sanctum_JBjDvwoEpmFc7CmzBaktFtZPGfSpXcEVA5YgBQ380d322d92";
|
||||||
final response = await http.get(
|
final response = await http.get(
|
||||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/index'),
|
Uri.parse(dotenv.env['SERVER_ROOT']! + '/diary/index'),
|
||||||
headers: {
|
headers: {
|
||||||
@@ -41,12 +43,16 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
|||||||
// Обновляем значения контроллеров только если они уже были созданы
|
// Обновляем значения контроллеров только если они уже были созданы
|
||||||
print(currentState.wakeupController);
|
print(currentState.wakeupController);
|
||||||
emit((currentState).copyWith(
|
emit((currentState).copyWith(
|
||||||
|
wakeupExpanded: currentState.wakeupExpanded,
|
||||||
|
retireExpanded: currentState.retireExpanded,
|
||||||
wakeupController: currentState.wakeupController,
|
wakeupController: currentState.wakeupController,
|
||||||
retireController: currentState.retireController,
|
retireController: currentState.retireController,
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
// Если текущее состояние - начальное, создаем новое загруженное состояние
|
// Если текущее состояние - начальное, создаем новое загруженное состояние
|
||||||
emit(DiaryEditLoadedState(
|
emit(DiaryEditLoadedState(
|
||||||
|
wakeupExpanded: true,
|
||||||
|
retireExpanded: false,
|
||||||
wakeupController: TimeOfDay.now(),
|
wakeupController: TimeOfDay.now(),
|
||||||
retireController: TimeOfDay.now(),
|
retireController: TimeOfDay.now(),
|
||||||
));
|
));
|
||||||
@@ -65,4 +71,9 @@ class DiaryEditBloc extends Bloc<DiaryEditEvent, DiaryEditState> {
|
|||||||
emit(DiaryEditErrorState('Ошибка при получении данных профиля: $e'));
|
emit(DiaryEditErrorState('Ошибка при получении данных профиля: $e'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*_expandWakeup(
|
||||||
|
ToggleWakeupExpandedEvent event, Emitter<DiaryEditLoadedState> emit) {
|
||||||
|
emit(state.copyWith(wakeupExpanded: !state.wakeupExpanded));
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,3 +14,5 @@ class DiaryEditInitialEvent extends DiaryEditEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object?> get props => [];
|
List<Object?> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ToggleWakeupExpandedEvent extends DiaryEditEvent {}
|
||||||
|
|||||||
@@ -19,12 +19,18 @@ class DiaryEditInitialState extends DiaryEditState {
|
|||||||
/// Represents the state of DiaryEdit in the application.
|
/// Represents the state of DiaryEdit in the application.
|
||||||
class DiaryEditLoadedState extends DiaryEditState {
|
class DiaryEditLoadedState extends DiaryEditState {
|
||||||
DiaryEditLoadedState(
|
DiaryEditLoadedState(
|
||||||
{this.diaryEditModelObj, this.wakeupController, this.retireController})
|
{this.diaryEditModelObj,
|
||||||
|
this.wakeupController,
|
||||||
|
this.retireController,
|
||||||
|
required this.wakeupExpanded,
|
||||||
|
required this.retireExpanded})
|
||||||
: super(diaryEditModelObj: null);
|
: super(diaryEditModelObj: null);
|
||||||
|
|
||||||
DiaryEditModel? diaryEditModelObj;
|
DiaryEditModel? diaryEditModelObj;
|
||||||
TimeOfDay? wakeupController;
|
TimeOfDay? wakeupController;
|
||||||
TimeOfDay? retireController;
|
TimeOfDay? retireController;
|
||||||
|
bool wakeupExpanded;
|
||||||
|
bool retireExpanded;
|
||||||
@override
|
@override
|
||||||
List<Object?> get props =>
|
List<Object?> get props =>
|
||||||
[diaryEditModelObj, wakeupController, retireController];
|
[diaryEditModelObj, wakeupController, retireController];
|
||||||
@@ -32,12 +38,15 @@ class DiaryEditLoadedState extends DiaryEditState {
|
|||||||
DiaryEditModel? diaryEditModelObj,
|
DiaryEditModel? diaryEditModelObj,
|
||||||
TimeOfDay? wakeupController,
|
TimeOfDay? wakeupController,
|
||||||
TimeOfDay? retireController,
|
TimeOfDay? retireController,
|
||||||
|
required bool wakeupExpanded,
|
||||||
|
required bool retireExpanded,
|
||||||
}) {
|
}) {
|
||||||
return DiaryEditLoadedState(
|
return DiaryEditLoadedState(
|
||||||
diaryEditModelObj: diaryEditModelObj ?? this.diaryEditModelObj,
|
diaryEditModelObj: diaryEditModelObj ?? this.diaryEditModelObj,
|
||||||
wakeupController: wakeupController ?? this.wakeupController,
|
wakeupController: wakeupController ?? this.wakeupController,
|
||||||
retireController: retireController ?? this.retireController,
|
retireController: retireController ?? this.retireController,
|
||||||
);
|
wakeupExpanded: wakeupExpanded,
|
||||||
|
retireExpanded: retireExpanded);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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_edit_drop_down.dart';
|
||||||
import 'package:eatvio_app/widgets/custom_outlined_button.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_icon_button.dart';
|
||||||
import 'package:eatvio_app/widgets/custom_expandable_list_card.dart';
|
|
||||||
|
|
||||||
// ignore: must_be_immutable
|
// ignore: must_be_immutable
|
||||||
class DiaryEditScreen extends StatelessWidget {
|
class DiaryEditScreen extends StatelessWidget {
|
||||||
@@ -91,7 +90,7 @@ class DiaryEditScreen extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
_buildHeaderRow(context),
|
_buildHeaderRow(context),
|
||||||
SizedBox(height: 30.v),
|
SizedBox(height: 30.v),
|
||||||
_buildWakupRetire(),
|
_buildWakupRetire(context, state),
|
||||||
SizedBox(height: 30.v),
|
SizedBox(height: 30.v),
|
||||||
_buildImageStack(context),
|
_buildImageStack(context),
|
||||||
SizedBox(height: 20.v),
|
SizedBox(height: 20.v),
|
||||||
@@ -780,10 +779,71 @@ class DiaryEditScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildWakupRetire() {
|
Widget _buildWakupRetire(BuildContext context, DiaryEditLoadedState state) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 16.h),
|
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<DiaryEditBloc>(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<String> moodList) {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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<ExpandableList> {
|
|
||||||
bool isExpanded = false;
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return BlocBuilder<DiaryEditBloc, DiaryEditState>(
|
|
||||||
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<void> _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;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user