forked from eatvio/eatvio_app
feat(app): Recipe layouts
This commit is contained in:
@@ -16,6 +16,9 @@ class RecipeCreateBloc extends Bloc<RecipeCreateEvent, RecipeCreateState> {
|
|||||||
RecipeCreateBloc(RecipeCreateState initialState) : super(initialState) {
|
RecipeCreateBloc(RecipeCreateState initialState) : super(initialState) {
|
||||||
on<RecipeCreateInitialEvent>(_onInitialize);
|
on<RecipeCreateInitialEvent>(_onInitialize);
|
||||||
on<CreateRecipe>(_createRecipe);
|
on<CreateRecipe>(_createRecipe);
|
||||||
|
on<AddStep>(_addStep);
|
||||||
|
on<RemoveStep>(_removeStep);
|
||||||
|
on<ReloadScreen>(_reloadScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onInitialize(
|
_onInitialize(
|
||||||
@@ -34,22 +37,65 @@ class RecipeCreateBloc extends Bloc<RecipeCreateEvent, RecipeCreateState> {
|
|||||||
emit(currentState.copyWith(
|
emit(currentState.copyWith(
|
||||||
recipeModelObj: currentState.recipeModelObj,
|
recipeModelObj: currentState.recipeModelObj,
|
||||||
title: currentState.title,
|
title: currentState.title,
|
||||||
|
token: currentState.token,
|
||||||
description: currentState.description,
|
description: currentState.description,
|
||||||
video_url: currentState.video_url,
|
video_url: currentState.video_url,
|
||||||
steps: currentState.steps));
|
steps: currentState.steps,
|
||||||
|
stepDescriptions: currentState.stepDescriptions,
|
||||||
|
tags: currentState.tags));
|
||||||
} else {
|
} else {
|
||||||
final Map<String, dynamic> step = {
|
final Map<String, dynamic> step = {
|
||||||
'description': '',
|
'description': '',
|
||||||
'image': '',
|
'image': '',
|
||||||
};
|
};
|
||||||
emit(RecipeCreateLoadedState(
|
emit(RecipeCreateLoadedState(
|
||||||
|
token: token,
|
||||||
title: TextEditingController(),
|
title: TextEditingController(),
|
||||||
description: TextEditingController(),
|
description: TextEditingController(),
|
||||||
video_url: TextEditingController(),
|
video_url: TextEditingController(),
|
||||||
|
tags: TextEditingController(),
|
||||||
|
stepDescriptions: [TextEditingController()],
|
||||||
steps: [step]));
|
steps: [step]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _addStep(
|
||||||
|
AddStep event, Emitter<RecipeCreateState> emit) async {
|
||||||
|
if (state is RecipeCreateLoadedState) {
|
||||||
|
var currentState = state as RecipeCreateLoadedState;
|
||||||
|
|
||||||
|
List<dynamic>? updatedSteps = currentState.steps;
|
||||||
|
List<TextEditingController>? updatedStepDescriptions =
|
||||||
|
currentState.stepDescriptions;
|
||||||
|
|
||||||
|
updatedSteps!.add({
|
||||||
|
'description': '',
|
||||||
|
'image': '',
|
||||||
|
});
|
||||||
|
updatedStepDescriptions!.add(TextEditingController());
|
||||||
|
emit(currentState.copyWith(
|
||||||
|
steps: updatedSteps, stepDescriptions: updatedStepDescriptions));
|
||||||
|
await _reloadScreen(event, emit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _removeStep(
|
||||||
|
RemoveStep event, Emitter<RecipeCreateState> emit) async {
|
||||||
|
if (state is RecipeCreateLoadedState) {
|
||||||
|
var currentState = state as RecipeCreateLoadedState;
|
||||||
|
|
||||||
|
List<dynamic>? updatedSteps = currentState.steps;
|
||||||
|
List<TextEditingController>? updatedStepDescriptions =
|
||||||
|
currentState.stepDescriptions;
|
||||||
|
|
||||||
|
updatedSteps!.removeAt(event.id);
|
||||||
|
updatedStepDescriptions!.removeAt(event.id);
|
||||||
|
emit(currentState.copyWith(
|
||||||
|
steps: updatedSteps, stepDescriptions: updatedStepDescriptions));
|
||||||
|
await _reloadScreen(event, emit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FutureOr<void> _createRecipe(
|
FutureOr<void> _createRecipe(
|
||||||
CreateRecipe event, Emitter<RecipeCreateState> emit) async {
|
CreateRecipe event, Emitter<RecipeCreateState> emit) async {
|
||||||
if (state is RecipeCreateLoadedState) {
|
if (state is RecipeCreateLoadedState) {
|
||||||
@@ -59,6 +105,7 @@ class RecipeCreateBloc extends Bloc<RecipeCreateEvent, RecipeCreateState> {
|
|||||||
currentState.title?.text,
|
currentState.title?.text,
|
||||||
currentState.video_url?.text,
|
currentState.video_url?.text,
|
||||||
currentState.description?.text,
|
currentState.description?.text,
|
||||||
|
currentState.steps,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
@@ -70,17 +117,14 @@ class RecipeCreateBloc extends Bloc<RecipeCreateEvent, RecipeCreateState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<http.Response> sendRecipe(
|
FutureOr<http.Response> sendRecipe(String? title, String? video_url,
|
||||||
String? title,
|
String? description, List<dynamic>? steps) async {
|
||||||
String? video_url,
|
|
||||||
String? description,
|
|
||||||
) async {
|
|
||||||
String url = '${dotenv.env['SERVER_ROOT']!}/recipe/create';
|
String url = '${dotenv.env['SERVER_ROOT']!}/recipe/create';
|
||||||
|
|
||||||
final Map<String, dynamic> credentials = {
|
final Map<String, dynamic> credentials = {
|
||||||
'title': title,
|
'title': title,
|
||||||
'description': description,
|
'description': description,
|
||||||
'video_url': video_url,
|
'video_url': video_url,
|
||||||
|
'steps': steps,
|
||||||
'status': 'active',
|
'status': 'active',
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -95,4 +139,28 @@ class RecipeCreateBloc extends Bloc<RecipeCreateEvent, RecipeCreateState> {
|
|||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _reloadScreen(
|
||||||
|
RecipeCreateEvent? event, Emitter<RecipeCreateState> emit) async {
|
||||||
|
print('Reloading..');
|
||||||
|
final box = await Hive.openBox('token');
|
||||||
|
final token = box.get('token');
|
||||||
|
if (token == null) {
|
||||||
|
NavigatorService.popAndPushNamed(
|
||||||
|
AppRoutes.authScreen,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (state is RecipeCreateLoadedState) {
|
||||||
|
var currentState = state as RecipeCreateLoadedState;
|
||||||
|
emit(currentState.copyWith(
|
||||||
|
recipeModelObj: currentState.recipeModelObj,
|
||||||
|
title: currentState.title,
|
||||||
|
token: currentState.token,
|
||||||
|
description: currentState.description,
|
||||||
|
video_url: currentState.video_url,
|
||||||
|
steps: currentState.steps,
|
||||||
|
stepDescriptions: currentState.stepDescriptions,
|
||||||
|
tags: currentState.tags));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,3 +19,22 @@ class CreateRecipe extends RecipeCreateEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object?> get props => [];
|
List<Object?> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AddStep extends RecipeCreateEvent {
|
||||||
|
AddStep();
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class RemoveStep extends RecipeCreateEvent {
|
||||||
|
RemoveStep(this.id);
|
||||||
|
final int id;
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [id];
|
||||||
|
}
|
||||||
|
|
||||||
|
class ReloadScreen extends RecipeCreateEvent {
|
||||||
|
ReloadScreen();
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [];
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,33 +24,52 @@ class RecipeCreateState extends Equatable {
|
|||||||
class RecipeCreateLoadedState extends RecipeCreateState {
|
class RecipeCreateLoadedState extends RecipeCreateState {
|
||||||
RecipeCreateLoadedState(
|
RecipeCreateLoadedState(
|
||||||
{this.recipeModelObj,
|
{this.recipeModelObj,
|
||||||
|
this.token,
|
||||||
this.title,
|
this.title,
|
||||||
this.description,
|
this.description,
|
||||||
this.video_url,
|
this.video_url,
|
||||||
|
this.tags,
|
||||||
|
this.stepDescriptions,
|
||||||
this.steps});
|
this.steps});
|
||||||
|
|
||||||
RecipeCreateModel? recipeModelObj;
|
RecipeCreateModel? recipeModelObj;
|
||||||
|
String? token;
|
||||||
TextEditingController? title;
|
TextEditingController? title;
|
||||||
TextEditingController? description;
|
TextEditingController? description;
|
||||||
TextEditingController? video_url;
|
TextEditingController? video_url;
|
||||||
|
TextEditingController? tags;
|
||||||
List<dynamic>? steps;
|
List<dynamic>? steps;
|
||||||
|
List<TextEditingController>? stepDescriptions;
|
||||||
@override
|
@override
|
||||||
List<Object?> get props =>
|
List<Object?> get props => [
|
||||||
[recipeModelObj, title, description, video_url, steps];
|
recipeModelObj,
|
||||||
|
title,
|
||||||
|
token,
|
||||||
|
description,
|
||||||
|
video_url,
|
||||||
|
steps,
|
||||||
|
tags,
|
||||||
|
stepDescriptions
|
||||||
|
];
|
||||||
RecipeCreateLoadedState copyWith({
|
RecipeCreateLoadedState copyWith({
|
||||||
RecipeCreateModel? recipeModelObj,
|
RecipeCreateModel? recipeModelObj,
|
||||||
|
String? token,
|
||||||
TextEditingController? title,
|
TextEditingController? title,
|
||||||
TextEditingController? description,
|
TextEditingController? description,
|
||||||
TextEditingController? video_url,
|
TextEditingController? video_url,
|
||||||
|
TextEditingController? tags,
|
||||||
List<dynamic>? steps,
|
List<dynamic>? steps,
|
||||||
|
List<TextEditingController>? stepDescriptions,
|
||||||
}) {
|
}) {
|
||||||
return RecipeCreateLoadedState(
|
return RecipeCreateLoadedState(
|
||||||
recipeModelObj: recipeModelObj ?? this.recipeModelObj,
|
recipeModelObj: recipeModelObj ?? this.recipeModelObj,
|
||||||
title: title ?? this.title,
|
title: title ?? this.title,
|
||||||
description: description ?? this.description,
|
description: description ?? this.description,
|
||||||
video_url: video_url ?? this.video_url,
|
video_url: video_url ?? this.video_url,
|
||||||
steps: steps ?? this.steps,
|
token: token ?? this.token,
|
||||||
);
|
steps: steps ?? this.steps,
|
||||||
|
tags: tags ?? this.tags,
|
||||||
|
stepDescriptions: stepDescriptions ?? this.stepDescriptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ import 'package:eatvio_app/widgets/custom_outlined_button.dart';
|
|||||||
|
|
||||||
class RecipeCreateScreen extends StatelessWidget {
|
class RecipeCreateScreen extends StatelessWidget {
|
||||||
const RecipeCreateScreen({Key? key}) : super(key: key);
|
const RecipeCreateScreen({Key? key}) : super(key: key);
|
||||||
|
|
||||||
static Widget builder(BuildContext context) {
|
static Widget builder(BuildContext context) {
|
||||||
final recipeID = ModalRoute.of(context)!.settings.arguments;
|
final recipeID = ModalRoute.of(context)!.settings.arguments;
|
||||||
return BlocProvider<RecipeCreateBloc>(
|
return BlocProvider<RecipeCreateBloc>(
|
||||||
create: (context) =>
|
create: (context) => RecipeCreateBloc(RecipeCreateState(
|
||||||
RecipeCreateBloc(RecipeCreateState(recipeModelObj: RecipeCreateModel(recipeID: recipeID.toString())))..add(RecipeCreateInitialEvent()),
|
recipeModelObj: RecipeCreateModel(recipeID: recipeID.toString())))
|
||||||
|
..add(RecipeCreateInitialEvent()),
|
||||||
child: RecipeCreateScreen());
|
child: RecipeCreateScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,29 +50,27 @@ class RecipeCreateScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return SafeArea(
|
return RefreshIndicator(
|
||||||
child: Scaffold(
|
onRefresh: refreshPage(context),
|
||||||
resizeToAvoidBottomInset: false,
|
child: SafeArea(
|
||||||
body: Container(
|
child: Scaffold(
|
||||||
width: double.maxFinite,
|
resizeToAvoidBottomInset: false,
|
||||||
decoration: BoxDecoration(color: Colors.grey[200]),
|
body: Container(
|
||||||
child: ListView(
|
width: double.maxFinite,
|
||||||
children: [
|
decoration: BoxDecoration(color: Colors.grey[200]),
|
||||||
_buldAppBar(context),
|
child: ListView(children: [
|
||||||
SizedBox(height: 20.v),
|
_buldAppBar(context),
|
||||||
_buildRecipeInfo(state, context),
|
SizedBox(height: 20.v),
|
||||||
SizedBox(height: 20.v),
|
_buildRecipeInfo(state, context),
|
||||||
Column(
|
SizedBox(height: 20.v),
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
Column(
|
||||||
children: steps,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
),
|
children: steps,
|
||||||
SizedBox(height: 20.v),
|
),
|
||||||
_buildAdditional(context, state)
|
SizedBox(height: 20.v),
|
||||||
],
|
_buildAdditional(context, state)
|
||||||
),
|
]),
|
||||||
),
|
))));
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_buldAppBar(BuildContext context) {
|
_buldAppBar(BuildContext context) {
|
||||||
@@ -164,45 +162,50 @@ class RecipeCreateScreen extends StatelessWidget {
|
|||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_buildAddPhoto(BuildContext context, RecipeCreateLoadedState state) {
|
refreshPage(BuildContext context) {
|
||||||
bool isLoading = false;
|
return () async {
|
||||||
return GestureDetector(
|
context.read<RecipeCreateBloc>().add(ReloadScreen());
|
||||||
child: Stack(
|
};
|
||||||
children: [
|
}
|
||||||
if (!isLoading)
|
|
||||||
Container(
|
_buildAddPhoto(BuildContext context, RecipeCreateLoadedState state) {
|
||||||
padding: EdgeInsets.symmetric(
|
bool isLoading = false;
|
||||||
horizontal: 40.h,
|
return GestureDetector(
|
||||||
vertical: 80.v,
|
child: Stack(
|
||||||
),
|
children: [
|
||||||
decoration: AppDecoration.fillGray.copyWith(
|
if (!isLoading)
|
||||||
borderRadius: BorderRadiusStyle.roundedBorder5,
|
Container(
|
||||||
),
|
padding: EdgeInsets.symmetric(
|
||||||
child: Row(
|
horizontal: 40.h,
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
vertical: 80.v,
|
||||||
mainAxisSize: MainAxisSize.min,
|
),
|
||||||
children: [
|
decoration: AppDecoration.fillGray.copyWith(
|
||||||
Padding(
|
borderRadius: BorderRadiusStyle.roundedBorder5,
|
||||||
padding: EdgeInsets.only(
|
),
|
||||||
left: 7.h,
|
child: Row(
|
||||||
top: 5.v,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
left: 7.h,
|
||||||
|
top: 5.v,
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
"Добавить фото",
|
||||||
|
selectionColor: appTheme.blueA400,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: Text(
|
Spacer(),
|
||||||
"Добавить фото",
|
Icon(
|
||||||
selectionColor: appTheme.blueA400,
|
Icons.photo_library,
|
||||||
),
|
color: appTheme.blueGray300,
|
||||||
),
|
)
|
||||||
Spacer(),
|
],
|
||||||
Icon(
|
),
|
||||||
Icons.photo_library,
|
|
||||||
color: appTheme.blueGray300,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
/*if (isLoading)
|
||||||
/*if (isLoading)
|
|
||||||
Container(
|
Container(
|
||||||
margin: EdgeInsets.symmetric(horizontal: 10.h),
|
margin: EdgeInsets.symmetric(horizontal: 10.h),
|
||||||
padding: EdgeInsets.symmetric(
|
padding: EdgeInsets.symmetric(
|
||||||
@@ -218,155 +221,173 @@ _buildAddPhoto(BuildContext context, RecipeCreateLoadedState state) {
|
|||||||
.blueGray300), // Замените на свой прелоадер при необходимости
|
.blueGray300), // Замените на свой прелоадер при необходимости
|
||||||
),
|
),
|
||||||
),*/
|
),*/
|
||||||
],
|
],
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
_buildStep(BuildContext context, RecipeCreateLoadedState state, int i) {
|
|
||||||
bool isLastStep = i == state.steps!.length - 1;
|
|
||||||
bool isFirstStep = i == 0;
|
|
||||||
|
|
||||||
return Container(
|
|
||||||
margin: EdgeInsets.only(
|
|
||||||
left: 16.h,
|
|
||||||
right: 16.h,
|
|
||||||
bottom: 10.h,
|
|
||||||
),
|
|
||||||
padding: EdgeInsets.all(12.h),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.white,
|
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Colors.grey.withOpacity(0.5),
|
|
||||||
spreadRadius: 2,
|
|
||||||
blurRadius: 5,
|
|
||||||
offset: Offset(0, 3),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
|
||||||
Align(
|
|
||||||
alignment: Alignment.centerLeft,
|
|
||||||
child: Text(
|
|
||||||
"Шаг ${i + 1}",
|
|
||||||
style: CustomTextStyles.titleMediumSemiBold,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
SizedBox(height: 8.0),
|
);
|
||||||
CustomTextFormField(
|
}
|
||||||
controller: state.description,
|
|
||||||
hintText: "Введите описание шага",
|
_buildStep(BuildContext context, RecipeCreateLoadedState state, int i) {
|
||||||
maxLines: 4,
|
bool isLastStep = i == state.steps!.length - 1;
|
||||||
fillColor: appTheme.gray50,
|
bool isFirstStep = i == 0;
|
||||||
borderDecoration: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(5.h),
|
return Container(
|
||||||
borderSide: BorderSide(
|
margin: EdgeInsets.only(
|
||||||
color: appTheme.gray50,
|
left: 16.h,
|
||||||
width: 1,
|
right: 16.h,
|
||||||
|
bottom: 10.h,
|
||||||
|
),
|
||||||
|
padding: EdgeInsets.all(12.h),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.grey.withOpacity(0.5),
|
||||||
|
spreadRadius: 2,
|
||||||
|
blurRadius: 5,
|
||||||
|
offset: Offset(0, 3),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Text(
|
||||||
|
"Шаг ${i + 1}",
|
||||||
|
style: CustomTextStyles.titleMediumSemiBold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
SizedBox(height: 8.0),
|
||||||
SizedBox(height: 16.0),
|
CustomTextFormField(
|
||||||
_buildAddPhoto(context, state),
|
controller: state.stepDescriptions?[i],
|
||||||
if (!isFirstStep)
|
hintText: "Введите описание шага",
|
||||||
Row(
|
maxLines: 4,
|
||||||
children: [
|
fillColor: appTheme.gray50,
|
||||||
Flexible(
|
borderDecoration: OutlineInputBorder(
|
||||||
flex: 5,
|
borderRadius: BorderRadius.circular(5.h),
|
||||||
child: CustomOutlinedButton(
|
borderSide: BorderSide(
|
||||||
text: "Добавить шаг",
|
color: appTheme.gray50,
|
||||||
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
width: 1,
|
||||||
),
|
|
||||||
),
|
),
|
||||||
SizedBox(width: 8), // Add some spacing between the buttons
|
),
|
||||||
Flexible(
|
|
||||||
flex: 1,
|
|
||||||
child: CustomOutlinedButton(
|
|
||||||
text: "х",
|
|
||||||
onPressed: () => Navigator.pushNamed(
|
|
||||||
context,
|
|
||||||
AppRoutes.blogPostCreateScreen,
|
|
||||||
),
|
|
||||||
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
if (isLastStep) // Добавляем кнопку "Добавить шаг" только для последнего шага
|
|
||||||
SizedBox(height: 16.0),
|
SizedBox(height: 16.0),
|
||||||
CustomOutlinedButton(
|
_buildAddPhoto(context, state),
|
||||||
text: "Добавить шаг",
|
SizedBox(height: 16.0),
|
||||||
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
if (isFirstStep && isLastStep)
|
||||||
),
|
CustomOutlinedButton(
|
||||||
]),
|
onPressed: () => context.read<RecipeCreateBloc>().add(AddStep()),
|
||||||
);
|
text: "Добавить шаг",
|
||||||
}
|
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||||
|
),
|
||||||
|
if (isLastStep &&
|
||||||
|
!isFirstStep) // Добавляем кнопку "Добавить шаг" только для последнего шага
|
||||||
|
Column(
|
||||||
|
children: [
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Flexible(
|
||||||
|
flex: 5,
|
||||||
|
child: CustomOutlinedButton(
|
||||||
|
onPressed: () =>
|
||||||
|
context.read<RecipeCreateBloc>().add(AddStep()),
|
||||||
|
text: "Добавить шаг",
|
||||||
|
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 8), // Add some spacing between the buttons
|
||||||
|
Flexible(
|
||||||
|
flex: 1,
|
||||||
|
child: CustomOutlinedButton(
|
||||||
|
text: "х",
|
||||||
|
onPressed: () =>
|
||||||
|
context.read<RecipeCreateBloc>().add(RemoveStep(i)),
|
||||||
|
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
if (!isLastStep && !isFirstStep)
|
||||||
|
CustomOutlinedButton(
|
||||||
|
onPressed: () =>
|
||||||
|
context.read<RecipeCreateBloc>().add(RemoveStep(i)),
|
||||||
|
text: "x",
|
||||||
|
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
_buildAdditional(BuildContext context, RecipeCreateLoadedState state) {
|
_buildAdditional(BuildContext context, RecipeCreateLoadedState state) {
|
||||||
return Container(
|
return Container(
|
||||||
margin: EdgeInsets.only(
|
margin: EdgeInsets.only(
|
||||||
left: 16.h,
|
left: 16.h,
|
||||||
right: 16.h,
|
right: 16.h,
|
||||||
bottom: 10.h,
|
bottom: 10.h,
|
||||||
),
|
),
|
||||||
padding: EdgeInsets.all(12.h),
|
padding: EdgeInsets.all(12.h),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: Colors.grey.withOpacity(0.5),
|
color: Colors.grey.withOpacity(0.5),
|
||||||
spreadRadius: 2,
|
spreadRadius: 2,
|
||||||
blurRadius: 5,
|
blurRadius: 5,
|
||||||
offset: Offset(0, 3),
|
offset: Offset(0, 3),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||||
Align(alignment: Alignment.centerLeft, child: Text("Теги")),
|
Align(alignment: Alignment.centerLeft, child: Text("Теги")),
|
||||||
CustomTextFormField(
|
CustomTextFormField(
|
||||||
controller: state.title,
|
controller: state.tags,
|
||||||
hintText: "Введите теги, через запятую",
|
hintText: "Введите теги, через запятую",
|
||||||
fillColor: appTheme.gray50,
|
fillColor: appTheme.gray50,
|
||||||
borderDecoration: OutlineInputBorder(
|
borderDecoration: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(5.h),
|
borderRadius: BorderRadius.circular(5.h),
|
||||||
borderSide: BorderSide(
|
borderSide: BorderSide(
|
||||||
color: appTheme.gray50,
|
color: appTheme.gray50,
|
||||||
width: 1,
|
width: 1,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
SizedBox(height: 8.0),
|
||||||
SizedBox(height: 8.0),
|
Align(
|
||||||
Align(alignment: Alignment.centerLeft, child: Text("Ссылка на видео (необязательно)")),
|
alignment: Alignment.centerLeft,
|
||||||
CustomTextFormField(
|
child: Text("Ссылка на видео (необязательно)")),
|
||||||
controller: state.description,
|
CustomTextFormField(
|
||||||
hintText: "YouTube",
|
controller: state.video_url,
|
||||||
fillColor: appTheme.gray50,
|
hintText: "YouTube",
|
||||||
borderDecoration: OutlineInputBorder(
|
fillColor: appTheme.gray50,
|
||||||
borderRadius: BorderRadius.circular(5.h),
|
borderDecoration: OutlineInputBorder(
|
||||||
borderSide: BorderSide(
|
borderRadius: BorderRadius.circular(5.h),
|
||||||
color: appTheme.gray50,
|
borderSide: BorderSide(
|
||||||
width: 1,
|
color: appTheme.gray50,
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
SizedBox(height: 16.0),
|
||||||
SizedBox(height: 16.0),
|
CustomOutlinedButton(
|
||||||
CustomOutlinedButton(
|
text: "Добавить рецепт",
|
||||||
text: "Добавить рецепт",
|
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||||
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
),
|
||||||
),
|
]),
|
||||||
]),
|
);
|
||||||
);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Function onTapBack(BuildContext context) {
|
|
||||||
return () {
|
|
||||||
onTapArrowLeft(context);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
onTapArrowLeft(BuildContext context) {
|
Function onTapBack(BuildContext context) {
|
||||||
NavigatorService.goBack();
|
return () {
|
||||||
|
onTapArrowLeft(context);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
onTapArrowLeft(BuildContext context) {
|
||||||
|
NavigatorService.goBack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
|
|||||||
RecipeEditBloc(RecipeEditState initialState) : super(initialState) {
|
RecipeEditBloc(RecipeEditState initialState) : super(initialState) {
|
||||||
on<RecipeEditInitialEvent>(_onInitialize);
|
on<RecipeEditInitialEvent>(_onInitialize);
|
||||||
on<EditRecipe>(_editRecipe);
|
on<EditRecipe>(_editRecipe);
|
||||||
|
on<AddStep>(_addStep);
|
||||||
|
on<RemoveStep>(_removeStep);
|
||||||
|
on<ReloadScreen>(_reloadScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onInitialize(
|
_onInitialize(
|
||||||
@@ -44,16 +47,44 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
|
|||||||
var currentState = state as RecipeEditLoadedState;
|
var currentState = state as RecipeEditLoadedState;
|
||||||
emit(currentState.copyWith(
|
emit(currentState.copyWith(
|
||||||
recipeModelObj: currentState.recipeModelObj,
|
recipeModelObj: currentState.recipeModelObj,
|
||||||
recipe: currentState.recipe,
|
|
||||||
title: currentState.title,
|
title: currentState.title,
|
||||||
|
token: currentState.token,
|
||||||
|
recipe: currentState.recipe,
|
||||||
description: currentState.description,
|
description: currentState.description,
|
||||||
video_url: currentState.video_url));
|
video_url: currentState.video_url,
|
||||||
|
steps: currentState.steps,
|
||||||
|
stepDescriptions: currentState.stepDescriptions,
|
||||||
|
tags: currentState.tags));
|
||||||
} else {
|
} else {
|
||||||
|
final Map<String, dynamic> defaultStep = {
|
||||||
|
'description': '',
|
||||||
|
'image': '',
|
||||||
|
};
|
||||||
|
|
||||||
|
List<dynamic> steps = data['steps'];
|
||||||
|
List<TextEditingController> stepDescriptions = [];
|
||||||
|
|
||||||
|
if (data['steps'] == null) {
|
||||||
|
stepDescriptions.add(TextEditingController());
|
||||||
|
data['steps'].add(defaultStep);
|
||||||
|
} else {
|
||||||
|
for (var step in steps) {
|
||||||
|
stepDescriptions
|
||||||
|
.add(TextEditingController(text: step['description']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
emit(RecipeEditLoadedState(
|
emit(RecipeEditLoadedState(
|
||||||
recipe: data,
|
token: token,
|
||||||
title: TextEditingController(text: data['title']),
|
recipe: data,
|
||||||
description: TextEditingController(text: data['description']),
|
title: TextEditingController(text: data['title']),
|
||||||
video_url: TextEditingController(text: data['video_url'])));
|
description: TextEditingController(text: data['description']),
|
||||||
|
video_url: TextEditingController(text: data['video_url']),
|
||||||
|
tagsController: TextEditingController(),
|
||||||
|
tags: await _fetchTags(data['id']),
|
||||||
|
stepDescriptions: stepDescriptions,
|
||||||
|
steps: steps,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Один или несколько ключевых полей отсутствуют, обрабатываем ошибку
|
// Один или несколько ключевых полей отсутствуют, обрабатываем ошибку
|
||||||
@@ -92,6 +123,42 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _addStep(AddStep event, Emitter<RecipeEditState> emit) async {
|
||||||
|
if (state is RecipeEditLoadedState) {
|
||||||
|
var currentState = state as RecipeEditLoadedState;
|
||||||
|
|
||||||
|
List<dynamic>? updatedSteps = currentState.steps;
|
||||||
|
List<TextEditingController>? updatedStepDescriptions =
|
||||||
|
currentState.stepDescriptions;
|
||||||
|
|
||||||
|
updatedSteps!.add({
|
||||||
|
'description': '',
|
||||||
|
'image': '',
|
||||||
|
});
|
||||||
|
updatedStepDescriptions!.add(TextEditingController());
|
||||||
|
emit(currentState.copyWith(
|
||||||
|
steps: updatedSteps, stepDescriptions: updatedStepDescriptions));
|
||||||
|
await _reloadScreen(event, emit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _removeStep(
|
||||||
|
RemoveStep event, Emitter<RecipeEditState> emit) async {
|
||||||
|
if (state is RecipeEditLoadedState) {
|
||||||
|
var currentState = state as RecipeEditLoadedState;
|
||||||
|
|
||||||
|
List<dynamic>? updatedSteps = currentState.steps;
|
||||||
|
List<TextEditingController>? updatedStepDescriptions =
|
||||||
|
currentState.stepDescriptions;
|
||||||
|
|
||||||
|
updatedSteps!.removeAt(event.id);
|
||||||
|
updatedStepDescriptions!.removeAt(event.id);
|
||||||
|
emit(currentState.copyWith(
|
||||||
|
steps: updatedSteps, stepDescriptions: updatedStepDescriptions));
|
||||||
|
await _reloadScreen(event, emit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FutureOr<http.Response> sendRecipe(
|
FutureOr<http.Response> sendRecipe(
|
||||||
Map<String, dynamic>? recipe,
|
Map<String, dynamic>? recipe,
|
||||||
String? title,
|
String? title,
|
||||||
@@ -123,4 +190,49 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
|
|||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_fetchTags(int id) async {
|
||||||
|
final box = await Hive.openBox('token');
|
||||||
|
final token = box.get('token');
|
||||||
|
|
||||||
|
if (token == null) {
|
||||||
|
NavigatorService.popAndPushNamed(
|
||||||
|
AppRoutes.authScreen,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final response = await http.get(
|
||||||
|
Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipe/getTags/$id'),
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer $token',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
final data = jsonDecode(response.body);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _reloadScreen(
|
||||||
|
RecipeEditEvent? event, Emitter<RecipeEditState> emit) async {
|
||||||
|
print('Reloading..');
|
||||||
|
final box = await Hive.openBox('token');
|
||||||
|
final token = box.get('token');
|
||||||
|
if (token == null) {
|
||||||
|
NavigatorService.popAndPushNamed(
|
||||||
|
AppRoutes.authScreen,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (state is RecipeEditLoadedState) {
|
||||||
|
var currentState = state as RecipeEditLoadedState;
|
||||||
|
emit(currentState.copyWith(
|
||||||
|
recipeModelObj: currentState.recipeModelObj,
|
||||||
|
recipe: currentState.recipe,
|
||||||
|
title: currentState.title,
|
||||||
|
token: currentState.token,
|
||||||
|
description: currentState.description,
|
||||||
|
video_url: currentState.video_url,
|
||||||
|
steps: currentState.steps,
|
||||||
|
stepDescriptions: currentState.stepDescriptions,
|
||||||
|
tags: currentState.tags));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,3 +19,22 @@ class EditRecipe extends RecipeEditEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object?> get props => [];
|
List<Object?> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AddStep extends RecipeEditEvent {
|
||||||
|
AddStep();
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class RemoveStep extends RecipeEditEvent {
|
||||||
|
RemoveStep(this.id);
|
||||||
|
final int id;
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [id];
|
||||||
|
}
|
||||||
|
|
||||||
|
class ReloadScreen extends RecipeEditEvent {
|
||||||
|
ReloadScreen();
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [];
|
||||||
|
}
|
||||||
|
|||||||
@@ -24,32 +24,52 @@ class RecipeEditState extends Equatable {
|
|||||||
class RecipeEditLoadedState extends RecipeEditState {
|
class RecipeEditLoadedState extends RecipeEditState {
|
||||||
RecipeEditLoadedState(
|
RecipeEditLoadedState(
|
||||||
{this.recipeModelObj,
|
{this.recipeModelObj,
|
||||||
|
this.token,
|
||||||
this.recipe,
|
this.recipe,
|
||||||
this.title,
|
this.title,
|
||||||
this.description,
|
this.description,
|
||||||
this.video_url});
|
this.video_url,
|
||||||
|
this.tagsController,
|
||||||
|
this.stepDescriptions,
|
||||||
|
this.tags,
|
||||||
|
this.steps});
|
||||||
|
|
||||||
RecipeEditModel? recipeModelObj;
|
RecipeEditModel? recipeModelObj;
|
||||||
Map<String, dynamic>? recipe;
|
Map<String, dynamic>? recipe;
|
||||||
|
String? token;
|
||||||
TextEditingController? title;
|
TextEditingController? title;
|
||||||
TextEditingController? description;
|
TextEditingController? description;
|
||||||
TextEditingController? video_url;
|
TextEditingController? video_url;
|
||||||
|
TextEditingController? tagsController;
|
||||||
|
List<dynamic>? steps;
|
||||||
|
List<dynamic>? tags;
|
||||||
|
List<TextEditingController>? stepDescriptions;
|
||||||
@override
|
@override
|
||||||
List<Object?> get props =>
|
List<Object?> get props =>
|
||||||
[recipeModelObj, recipe, title, description, video_url];
|
[recipeModelObj, recipe, title, description, video_url];
|
||||||
RecipeEditLoadedState copyWith({
|
RecipeEditLoadedState copyWith({
|
||||||
RecipeEditModel? recipeModelObj,
|
RecipeEditModel? recipeModelObj,
|
||||||
Map<String, dynamic>? recipe,
|
Map<String, dynamic>? recipe,
|
||||||
|
String? token,
|
||||||
TextEditingController? title,
|
TextEditingController? title,
|
||||||
TextEditingController? description,
|
TextEditingController? description,
|
||||||
TextEditingController? video_url,
|
TextEditingController? video_url,
|
||||||
|
TextEditingController? tagsController,
|
||||||
|
List<dynamic>? steps,
|
||||||
|
List<dynamic>? tags,
|
||||||
|
List<TextEditingController>? stepDescriptions,
|
||||||
}) {
|
}) {
|
||||||
return RecipeEditLoadedState(
|
return RecipeEditLoadedState(
|
||||||
recipeModelObj: recipeModelObj ?? this.recipeModelObj,
|
recipeModelObj: recipeModelObj ?? this.recipeModelObj,
|
||||||
|
token: token ?? this.token,
|
||||||
recipe: recipe ?? this.recipe,
|
recipe: recipe ?? this.recipe,
|
||||||
title: title ?? this.title,
|
title: title ?? this.title,
|
||||||
description: description ?? this.description,
|
description: description ?? this.description,
|
||||||
video_url: video_url ?? this.video_url,
|
video_url: video_url ?? this.video_url,
|
||||||
|
tagsController: tagsController ?? this.tagsController,
|
||||||
|
steps: steps ?? this.steps,
|
||||||
|
tags: tags ?? this.tags,
|
||||||
|
stepDescriptions: stepDescriptions ?? this.stepDescriptions,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,23 @@
|
|||||||
import 'bloc/recipe_edit_bloc.dart';
|
import 'bloc/recipe_edit_bloc.dart';
|
||||||
import 'models/recipe_edit_model.dart';
|
import 'models/recipe_edit_model.dart';
|
||||||
import 'package:eatvio_app/core/app_export.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
|
import 'package:eatvio_app/core/app_export.dart';
|
||||||
|
import 'package:eatvio_app/widgets/app_bar/custom_app_bar.dart';
|
||||||
|
import 'package:eatvio_app/widgets/app_bar/appbar_leading_image.dart';
|
||||||
|
import 'package:eatvio_app/widgets/app_bar/appbar_subtitle.dart';
|
||||||
|
import 'package:eatvio_app/widgets/custom_text_form_field.dart';
|
||||||
|
import 'package:eatvio_app/widgets/custom_outlined_button.dart';
|
||||||
|
|
||||||
class RecipeEditScreen extends StatelessWidget {
|
class RecipeEditScreen extends StatelessWidget {
|
||||||
const RecipeEditScreen({Key? key}) : super(key: key);
|
const RecipeEditScreen({Key? key}) : super(key: key);
|
||||||
|
|
||||||
static Widget builder(BuildContext context) {
|
static Widget builder(BuildContext context) {
|
||||||
final recipeID = ModalRoute.of(context)!.settings.arguments;
|
final recipeID = ModalRoute.of(context)!.settings.arguments;
|
||||||
return BlocProvider<RecipeEditBloc>(
|
return BlocProvider<RecipeEditBloc>(
|
||||||
create: (context) => RecipeEditBloc(RecipeEditState(recipeModelObj: RecipeEditModel(recipeID: recipeID.toString())))..add(RecipeEditInitialEvent()),
|
create: (context) => RecipeEditBloc(RecipeEditState(
|
||||||
|
recipeModelObj: RecipeEditModel(recipeID: recipeID.toString())))
|
||||||
|
..add(RecipeEditInitialEvent()),
|
||||||
child: RecipeEditScreen());
|
child: RecipeEditScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,78 +45,385 @@ class RecipeEditScreen extends StatelessWidget {
|
|||||||
|
|
||||||
_buildRecipeEdit(BuildContext context, RecipeEditLoadedState state) {
|
_buildRecipeEdit(BuildContext context, RecipeEditLoadedState state) {
|
||||||
mediaQueryData = MediaQuery.of(context);
|
mediaQueryData = MediaQuery.of(context);
|
||||||
return SafeArea(
|
List<Widget> steps = [];
|
||||||
child: Scaffold(
|
if (state.steps != null) {
|
||||||
resizeToAvoidBottomInset: false,
|
for (int i = 0; i < state.steps!.length; i++) {
|
||||||
body: Container(
|
steps.add(_buildStep(context, state, i));
|
||||||
width: double.maxFinite,
|
}
|
||||||
decoration: AppDecoration.fillGray,
|
}
|
||||||
child: ListView(
|
|
||||||
children: [
|
return RefreshIndicator(
|
||||||
SizedBox(height: 30.v),
|
onRefresh: refreshPage(context),
|
||||||
Container(
|
child: SafeArea(
|
||||||
margin: EdgeInsets.only(
|
child: Scaffold(
|
||||||
left: 16.h,
|
resizeToAvoidBottomInset: false,
|
||||||
right: 20.h,
|
body: Container(
|
||||||
bottom: 10.h,
|
width: double.maxFinite,
|
||||||
),
|
decoration: BoxDecoration(color: Colors.grey[200]),
|
||||||
padding: EdgeInsets.all(12.h),
|
child: ListView(children: [
|
||||||
decoration: BoxDecoration(
|
_buldAppBar(context),
|
||||||
color: Colors.white,
|
SizedBox(height: 20.v),
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
_buildRecipeInfo(state, context),
|
||||||
boxShadow: [
|
SizedBox(height: 20.v),
|
||||||
BoxShadow(
|
Column(
|
||||||
color: Colors.grey.withOpacity(0.5),
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
spreadRadius: 2,
|
children: steps,
|
||||||
blurRadius: 5,
|
|
||||||
offset: Offset(0, 3),
|
|
||||||
),
|
),
|
||||||
],
|
SizedBox(height: 20.v),
|
||||||
),
|
_buildAdditional(context, state)
|
||||||
child: Column(
|
]),
|
||||||
mainAxisSize: MainAxisSize.min,
|
))));
|
||||||
children: [
|
}
|
||||||
CachedNetworkImage(
|
|
||||||
imageUrl: dotenv.env['STORAGE_URL']! + (state.recipe?['image'] ?? ''),
|
_buldAppBar(BuildContext context) {
|
||||||
imageBuilder: (context, imageProvider) => CircleAvatar(
|
return Container(
|
||||||
backgroundImage: imageProvider,
|
margin: EdgeInsets.all(16.h),
|
||||||
radius: 25,
|
decoration: BoxDecoration(
|
||||||
),
|
color: Colors.white,
|
||||||
placeholder: (context, url) => CircularProgressIndicator(),
|
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||||
errorWidget: (context, url, error) => CircleAvatar(
|
boxShadow: [
|
||||||
child: Icon(Icons.person),
|
BoxShadow(
|
||||||
backgroundColor: Colors.white,
|
color: Colors.grey.withOpacity(0.5),
|
||||||
radius: 25,
|
spreadRadius: 2,
|
||||||
),
|
blurRadius: 5,
|
||||||
),
|
offset: Offset(0, 3),
|
||||||
SizedBox(height: 16.0),
|
|
||||||
TextFormField(
|
|
||||||
controller: state.title,
|
|
||||||
decoration: InputDecoration(labelText: 'Заголовок'),
|
|
||||||
),
|
|
||||||
SizedBox(height: 16.0),
|
|
||||||
TextFormField(
|
|
||||||
controller: state.description,
|
|
||||||
decoration: InputDecoration(labelText: 'Описание'),
|
|
||||||
),
|
|
||||||
SizedBox(height: 16.0),
|
|
||||||
TextFormField(
|
|
||||||
controller: state.video_url,
|
|
||||||
decoration: InputDecoration(labelText: 'Ссылка'),
|
|
||||||
),
|
|
||||||
SizedBox(height: 16.0),
|
|
||||||
// Здесь нужно добавить виджет для загрузки картинки
|
|
||||||
ElevatedButton(
|
|
||||||
onPressed: () => context.read<RecipeEditBloc>().add(EditRecipe()),
|
|
||||||
child: Text('Сохранить'),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: CustomAppBar(
|
||||||
|
height: 54.v,
|
||||||
|
leadingWidth: 28.h,
|
||||||
|
leading: AppbarLeadingImage(
|
||||||
|
imagePath: ImageConstant.imgArrowLeft,
|
||||||
|
margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v),
|
||||||
|
onTap: onTapBack(context),
|
||||||
),
|
),
|
||||||
|
title: Align(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: AppbarSubtitle(
|
||||||
|
text: "Редактирование рецепта",
|
||||||
|
)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_buildRecipeInfo(RecipeEditLoadedState state, BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
margin: EdgeInsets.only(
|
||||||
|
left: 16.h,
|
||||||
|
right: 16.h,
|
||||||
|
bottom: 10.h,
|
||||||
|
),
|
||||||
|
padding: EdgeInsets.all(12.h),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.grey.withOpacity(0.5),
|
||||||
|
spreadRadius: 2,
|
||||||
|
blurRadius: 5,
|
||||||
|
offset: Offset(0, 3),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
Align(alignment: Alignment.centerLeft, child: Text("Изображение")),
|
||||||
|
if (state.recipe?['image'] != null)
|
||||||
|
CachedNetworkImage(
|
||||||
|
imageUrl: dotenv.env['STORAGE_URL']! + (state.recipe?['image']),
|
||||||
|
width: double
|
||||||
|
.infinity, // Установите ширину равной ширине родительского элемента
|
||||||
|
height: 200.0,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
placeholder: (context, url) => CircularProgressIndicator(),
|
||||||
|
errorWidget: (context, url, error) => Icon(Icons.error),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
_buildAddPhoto(context, state),
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
Align(alignment: Alignment.centerLeft, child: Text("Название рецепта")),
|
||||||
|
CustomTextFormField(
|
||||||
|
controller: state.title,
|
||||||
|
hintText: "Введите название рецепта",
|
||||||
|
fillColor: appTheme.gray50,
|
||||||
|
borderDecoration: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(5.h),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: appTheme.gray50,
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
Align(alignment: Alignment.centerLeft, child: Text("Описание")),
|
||||||
|
CustomTextFormField(
|
||||||
|
controller: state.description,
|
||||||
|
hintText: "Введите описание рецепта",
|
||||||
|
maxLines: 4,
|
||||||
|
fillColor: appTheme.gray50,
|
||||||
|
borderDecoration: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(5.h),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: appTheme.gray50,
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshPage(BuildContext context) {
|
||||||
|
return () async {
|
||||||
|
context.read<RecipeEditBloc>().add(ReloadScreen());
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
_buildAddPhoto(BuildContext context, RecipeEditLoadedState state) {
|
||||||
|
bool isLoading = false;
|
||||||
|
return GestureDetector(
|
||||||
|
child: Stack(
|
||||||
|
children: [
|
||||||
|
if (!isLoading)
|
||||||
|
Container(
|
||||||
|
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,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
/*if (isLoading)
|
||||||
|
Container(
|
||||||
|
margin: EdgeInsets.symmetric(horizontal: 10.h),
|
||||||
|
padding: EdgeInsets.symmetric(
|
||||||
|
horizontal: 40.h,
|
||||||
|
vertical: 80.v,
|
||||||
|
),
|
||||||
|
decoration: AppDecoration.fillGray.copyWith(
|
||||||
|
borderRadius: BorderRadiusStyle.roundedBorder5,
|
||||||
|
),
|
||||||
|
child: Center(
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
color: appTheme
|
||||||
|
.blueGray300), // Замените на свой прелоадер при необходимости
|
||||||
|
),
|
||||||
|
),*/
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_buildStep(BuildContext context, RecipeEditLoadedState state, int i) {
|
||||||
|
bool isLastStep = i == state.steps!.length - 1;
|
||||||
|
bool isFirstStep = i == 0;
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
margin: EdgeInsets.only(
|
||||||
|
left: 16.h,
|
||||||
|
right: 16.h,
|
||||||
|
bottom: 10.h,
|
||||||
|
),
|
||||||
|
padding: EdgeInsets.all(12.h),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.grey.withOpacity(0.5),
|
||||||
|
spreadRadius: 2,
|
||||||
|
blurRadius: 5,
|
||||||
|
offset: Offset(0, 3),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Text(
|
||||||
|
"Шаг ${i + 1}",
|
||||||
|
style: CustomTextStyles.titleMediumSemiBold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 8.0),
|
||||||
|
CustomTextFormField(
|
||||||
|
controller: state.stepDescriptions?[i],
|
||||||
|
hintText: "Введите описание шага",
|
||||||
|
maxLines: 4,
|
||||||
|
fillColor: appTheme.gray50,
|
||||||
|
borderDecoration: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(5.h),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: appTheme.gray50,
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
if (state.steps?[i]['image'] != null)
|
||||||
|
CachedNetworkImage(
|
||||||
|
imageUrl: dotenv.env['STORAGE_URL']! + (state.steps?[i]['image']),
|
||||||
|
width: double
|
||||||
|
.infinity, // Установите ширину равной ширине родительского элемента
|
||||||
|
height: 200.0, // Задайте постоянную высоту элемента
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
placeholder: (context, url) => CircularProgressIndicator(),
|
||||||
|
errorWidget: (context, url, error) => Icon(Icons.error),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
_buildAddPhoto(context, state),
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
if (isFirstStep && isLastStep)
|
||||||
|
CustomOutlinedButton(
|
||||||
|
onPressed: () => context.read<RecipeEditBloc>().add(AddStep()),
|
||||||
|
text: "Добавить шаг",
|
||||||
|
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||||
|
),
|
||||||
|
if (isLastStep &&
|
||||||
|
!isFirstStep) // Добавляем кнопку "Добавить шаг" только для последнего шага
|
||||||
|
Column(
|
||||||
|
children: [
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Flexible(
|
||||||
|
flex: 5,
|
||||||
|
child: CustomOutlinedButton(
|
||||||
|
onPressed: () =>
|
||||||
|
context.read<RecipeEditBloc>().add(AddStep()),
|
||||||
|
text: "Добавить шаг",
|
||||||
|
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(width: 8), // Add some spacing between the buttons
|
||||||
|
Flexible(
|
||||||
|
flex: 1,
|
||||||
|
child: CustomOutlinedButton(
|
||||||
|
text: "х",
|
||||||
|
onPressed: () =>
|
||||||
|
context.read<RecipeEditBloc>().add(RemoveStep(i)),
|
||||||
|
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
if (!isLastStep && !isFirstStep)
|
||||||
|
CustomOutlinedButton(
|
||||||
|
onPressed: () => context.read<RecipeEditBloc>().add(RemoveStep(i)),
|
||||||
|
text: "x",
|
||||||
|
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_buildAdditional(BuildContext context, RecipeEditLoadedState state) {
|
||||||
|
return Container(
|
||||||
|
margin: EdgeInsets.only(
|
||||||
|
left: 16.h,
|
||||||
|
right: 16.h,
|
||||||
|
bottom: 10.h,
|
||||||
|
),
|
||||||
|
padding: EdgeInsets.all(12.h),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.grey.withOpacity(0.5),
|
||||||
|
spreadRadius: 2,
|
||||||
|
blurRadius: 5,
|
||||||
|
offset: Offset(0, 3),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||||
|
Align(alignment: Alignment.centerLeft, child: Text("Теги")),
|
||||||
|
_buildEditableTags(state.tags),
|
||||||
|
SizedBox(height: 8.0),
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Text("Ссылка на видео (необязательно)")),
|
||||||
|
CustomTextFormField(
|
||||||
|
controller: state.video_url,
|
||||||
|
hintText: "YouTube",
|
||||||
|
fillColor: appTheme.gray50,
|
||||||
|
borderDecoration: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(5.h),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: appTheme.gray50,
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
CustomOutlinedButton(
|
||||||
|
text: "Добавить рецепт",
|
||||||
|
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_buildEditableTags(List<dynamic>? tags) {
|
||||||
|
String initialText = tags!.map((tag) => tag['name']).join(', ');
|
||||||
|
|
||||||
|
return CustomTextFormField(
|
||||||
|
initialValue: initialText,
|
||||||
|
fillColor: appTheme.gray50,
|
||||||
|
borderDecoration: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(5.h),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: appTheme.gray50,
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onChanged: _trimTags,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _trimTags(newValue) {
|
||||||
|
List<String> newTagNames =
|
||||||
|
newValue!.split(',').map((tag) => tag.trim()).toList();
|
||||||
|
List<Map<String, dynamic>> newTags =
|
||||||
|
newTagNames.map((tagName) => {'name': tagName}).toList();
|
||||||
|
print(newTags);
|
||||||
|
}
|
||||||
|
|
||||||
|
Function onTapBack(BuildContext context) {
|
||||||
|
return () {
|
||||||
|
onTapArrowLeft(context);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
onTapArrowLeft(BuildContext context) {
|
||||||
|
NavigatorService.goBack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import '/core/app_export.dart';
|
import '/core/app_export.dart';
|
||||||
import 'package:eatvio_app/presentation/recipe/recipe_show_screen/models/recipe_show_model.dart';
|
import 'package:eatvio_app/presentation/recipe/recipe_show_screen/models/recipe_show_model.dart';
|
||||||
|
import 'package:eatvio_app/presentation/feed/blog_post_screen/models/comment_model.dart';
|
||||||
part 'recipe_show_event.dart';
|
part 'recipe_show_event.dart';
|
||||||
part 'recipe_show_state.dart';
|
part 'recipe_show_state.dart';
|
||||||
|
|
||||||
@@ -16,6 +18,7 @@ class RecipeBloc extends Bloc<RecipeEvent, RecipeState> {
|
|||||||
RecipeBloc(RecipeState initialState) : super(initialState) {
|
RecipeBloc(RecipeState initialState) : super(initialState) {
|
||||||
on<RecipeInitialEvent>(_onInitialize);
|
on<RecipeInitialEvent>(_onInitialize);
|
||||||
on<DeleteEntry>(_deleteEntry);
|
on<DeleteEntry>(_deleteEntry);
|
||||||
|
on<CreateComment>(_createComment);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onInitialize(
|
_onInitialize(
|
||||||
@@ -44,9 +47,21 @@ class RecipeBloc extends Bloc<RecipeEvent, RecipeState> {
|
|||||||
var currentState = state as RecipeLoadedState;
|
var currentState = state as RecipeLoadedState;
|
||||||
emit(currentState.copyWith(
|
emit(currentState.copyWith(
|
||||||
recipeModelObj: currentState.recipeModelObj,
|
recipeModelObj: currentState.recipeModelObj,
|
||||||
recipe: currentState.recipe));
|
recipe: currentState.recipe,
|
||||||
|
token: currentState.token,
|
||||||
|
commentController: currentState.commentController,
|
||||||
|
comments: currentState.comments,
|
||||||
|
steps: currentState.steps,
|
||||||
|
author: currentState.author));
|
||||||
} else {
|
} else {
|
||||||
emit(RecipeLoadedState(recipe: data));
|
emit(RecipeLoadedState(
|
||||||
|
token: token,
|
||||||
|
recipe: data,
|
||||||
|
steps: data['steps'],
|
||||||
|
author: await _fetchAuthor(data['id']),
|
||||||
|
comments: fillCommentList(await _fetchComments(data['id'])),
|
||||||
|
tags: await _fetchTags(data['id']),
|
||||||
|
commentController: TextEditingController()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Один или несколько ключевых полей отсутствуют, обрабатываем ошибку
|
// Один или несколько ключевых полей отсутствуют, обрабатываем ошибку
|
||||||
@@ -85,4 +100,115 @@ class RecipeBloc extends Bloc<RecipeEvent, RecipeState> {
|
|||||||
emit(RecipeErrorState('Ошибка: ${response.statusCode}'));
|
emit(RecipeErrorState('Ошибка: ${response.statusCode}'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _createComment(
|
||||||
|
CreateComment event, Emitter<RecipeState> emit) async {
|
||||||
|
if (state is RecipeLoadedState) {
|
||||||
|
var currentState = state as RecipeLoadedState;
|
||||||
|
// Отправляем данные по HTTP маршруту и ждем ответ
|
||||||
|
var response = await _sendCommentData(
|
||||||
|
currentState.token, event.body, currentState.recipe?['id']);
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
var updatedComments =
|
||||||
|
fillCommentList(await _fetchComments(currentState.recipe?['id']));
|
||||||
|
var updatedState = currentState.copyWith(
|
||||||
|
comments: updatedComments,
|
||||||
|
commentController:
|
||||||
|
TextEditingController(), // Clear the comment input field
|
||||||
|
);
|
||||||
|
emit(updatedState); // Emit the updated state to trigger a screen update
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_fetchAuthor(int id) async {
|
||||||
|
final box = await Hive.openBox('token');
|
||||||
|
final token = box.get('token');
|
||||||
|
|
||||||
|
if (token == null) {
|
||||||
|
NavigatorService.popAndPushNamed(
|
||||||
|
AppRoutes.authScreen,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final response = await http.get(
|
||||||
|
Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipe/getAuthor/$id'),
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer $token',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
final data = jsonDecode(response.body);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List> _fetchComments(int id) async {
|
||||||
|
final box = await Hive.openBox('token');
|
||||||
|
final token = box.get('token');
|
||||||
|
if (token == null) {
|
||||||
|
NavigatorService.popAndPushNamed(
|
||||||
|
AppRoutes.authScreen,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final response = await http.get(
|
||||||
|
Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipe/getComments/$id'),
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer $token',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
final data = jsonDecode(response.body);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
_fetchTags(int id) async {
|
||||||
|
final box = await Hive.openBox('token');
|
||||||
|
final token = box.get('token');
|
||||||
|
|
||||||
|
if (token == null) {
|
||||||
|
NavigatorService.popAndPushNamed(
|
||||||
|
AppRoutes.authScreen,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final response = await http.get(
|
||||||
|
Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipe/getTags/$id'),
|
||||||
|
headers: {
|
||||||
|
'Authorization': 'Bearer $token',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
final data = jsonDecode(response.body);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<CommentModel> fillCommentList(List<dynamic> comments) {
|
||||||
|
List<CommentModel> list = [];
|
||||||
|
for (int i = 0; i < comments.length; i++) {
|
||||||
|
list.add(CommentModel(
|
||||||
|
id: comments[i]['id'].toString(),
|
||||||
|
userImage: comments[i]['profile_photo_path'],
|
||||||
|
username: comments[i]['name'],
|
||||||
|
dateText: DateFormat('dd.MM')
|
||||||
|
.format(DateTime.parse(comments[i]['updated_at'])),
|
||||||
|
greetingText: comments[i]['body']));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<http.Response> _sendCommentData(
|
||||||
|
String? token, String body, int id) async {
|
||||||
|
String url = dotenv.env['SERVER_ROOT']! + '/recipe/createComment/$id';
|
||||||
|
final Map<String, dynamic> credentials = {
|
||||||
|
'id': id,
|
||||||
|
'body': body,
|
||||||
|
};
|
||||||
|
|
||||||
|
var response = await http.post(Uri.parse(url),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer $token',
|
||||||
|
},
|
||||||
|
body: json.encode(credentials),
|
||||||
|
encoding: utf8);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,3 +21,10 @@ class DeleteEntry extends RecipeEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object?> get props => [id];
|
List<Object?> get props => [id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CreateComment extends RecipeEvent {
|
||||||
|
CreateComment(this.body);
|
||||||
|
final String body;
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [body];
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,17 +22,52 @@ class RecipeState extends Equatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class RecipeLoadedState extends RecipeState {
|
class RecipeLoadedState extends RecipeState {
|
||||||
RecipeLoadedState({this.recipeModelObj, this.recipe});
|
RecipeLoadedState(
|
||||||
|
{this.recipeModelObj,
|
||||||
|
this.recipe,
|
||||||
|
this.author,
|
||||||
|
this.comments,
|
||||||
|
this.token,
|
||||||
|
this.commentController,
|
||||||
|
this.tags,
|
||||||
|
this.steps});
|
||||||
|
|
||||||
RecipeModel? recipeModelObj;
|
RecipeModel? recipeModelObj;
|
||||||
Map<String, dynamic>? recipe;
|
Map<String, dynamic>? recipe;
|
||||||
|
Map<String, dynamic>? author;
|
||||||
|
List<dynamic>? comments;
|
||||||
|
TextEditingController? commentController;
|
||||||
|
List<dynamic>? steps;
|
||||||
|
List<dynamic>? tags;
|
||||||
|
String? token;
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [recipeModelObj, recipe];
|
List<Object?> get props => [
|
||||||
|
recipeModelObj,
|
||||||
|
recipe,
|
||||||
|
author,
|
||||||
|
comments,
|
||||||
|
token,
|
||||||
|
commentController,
|
||||||
|
steps
|
||||||
|
];
|
||||||
RecipeLoadedState copyWith(
|
RecipeLoadedState copyWith(
|
||||||
{RecipeModel? recipeModelObj, Map<String, dynamic>? recipe}) {
|
{RecipeModel? recipeModelObj,
|
||||||
|
Map<String, dynamic>? recipe,
|
||||||
|
Map<String, dynamic>? author,
|
||||||
|
TextEditingController? commentController,
|
||||||
|
String? token,
|
||||||
|
List<dynamic>? tags,
|
||||||
|
List<dynamic>? steps,
|
||||||
|
List<dynamic>? comments}) {
|
||||||
return RecipeLoadedState(
|
return RecipeLoadedState(
|
||||||
recipeModelObj: recipeModelObj ?? this.recipeModelObj,
|
recipeModelObj: recipeModelObj ?? this.recipeModelObj,
|
||||||
recipe: recipe ?? this.recipe,
|
recipe: recipe ?? this.recipe,
|
||||||
|
author: author ?? this.author,
|
||||||
|
tags: tags ?? this.tags,
|
||||||
|
token: token ?? this.token,
|
||||||
|
commentController: commentController ?? this.commentController,
|
||||||
|
steps: steps ?? this.steps,
|
||||||
|
comments: comments ?? this.comments,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,22 @@
|
|||||||
import 'bloc/recipe_show_bloc.dart';
|
import 'bloc/recipe_show_bloc.dart';
|
||||||
import 'models/recipe_show_model.dart';
|
import 'models/recipe_show_model.dart';
|
||||||
|
import 'package:eatvio_app/presentation/feed/blog_post_screen/widgets/comment_widget.dart';
|
||||||
import 'package:eatvio_app/core/app_export.dart';
|
import 'package:eatvio_app/core/app_export.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:eatvio_app/widgets/custom_edit_text_form_field.dart';
|
||||||
|
import 'package:eatvio_app/widgets/custom_outlined_button.dart';
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
|
|
||||||
class RecipeScreen extends StatelessWidget {
|
class RecipeScreen extends StatelessWidget {
|
||||||
const RecipeScreen({Key? key}) : super(key: key);
|
const RecipeScreen({Key? key}) : super(key: key);
|
||||||
|
|
||||||
static Widget builder(BuildContext context) {
|
static Widget builder(BuildContext context) {
|
||||||
final recipeID = ModalRoute.of(context)!.settings.arguments;
|
final recipeID = ModalRoute.of(context)!.settings.arguments;
|
||||||
return BlocProvider<RecipeBloc>(
|
return BlocProvider<RecipeBloc>(
|
||||||
create: (context) => RecipeBloc(RecipeState(recipeModelObj: RecipeModel(recipeID: recipeID.toString())))..add(RecipeInitialEvent()),
|
create: (context) => RecipeBloc(RecipeState(
|
||||||
|
recipeModelObj: RecipeModel(recipeID: recipeID.toString())))
|
||||||
|
..add(RecipeInitialEvent()),
|
||||||
child: RecipeScreen());
|
child: RecipeScreen());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,87 +44,365 @@ class RecipeScreen extends StatelessWidget {
|
|||||||
|
|
||||||
_buildRecipe(BuildContext context, RecipeLoadedState state) {
|
_buildRecipe(BuildContext context, RecipeLoadedState state) {
|
||||||
mediaQueryData = MediaQuery.of(context);
|
mediaQueryData = MediaQuery.of(context);
|
||||||
|
List<Widget> steps = [];
|
||||||
|
if (state.steps != null) {
|
||||||
|
for (int i = 0; i < state.steps!.length; i++) {
|
||||||
|
steps.add(_buildStep(context, state, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
resizeToAvoidBottomInset: false,
|
resizeToAvoidBottomInset: false,
|
||||||
body: Container(
|
body: Container(
|
||||||
width: double.maxFinite,
|
width: double.maxFinite,
|
||||||
decoration: AppDecoration.fillGray,
|
decoration: AppDecoration.fillGray,
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: [
|
children: [
|
||||||
SizedBox(height: 30.v),
|
SizedBox(height: 15.v),
|
||||||
Container(
|
_buildHeaderRow(context, state),
|
||||||
margin: EdgeInsets.only(
|
SizedBox(height: 15.v),
|
||||||
left: 16.h,
|
_buildRecipeData(context, state),
|
||||||
right: 20.h,
|
SizedBox(height: 15.v),
|
||||||
bottom: 10.h,
|
Column(
|
||||||
),
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
padding: EdgeInsets.all(12.h),
|
children: steps,
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.white,
|
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: Colors.grey.withOpacity(0.5),
|
|
||||||
spreadRadius: 2,
|
|
||||||
blurRadius: 5,
|
|
||||||
offset: Offset(0, 3),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
|
||||||
CachedNetworkImage(
|
|
||||||
imageUrl: dotenv.env['STORAGE_URL']! + (state.recipe?['image'] ?? ''),
|
|
||||||
imageBuilder: (context, imageProvider) => CircleAvatar(
|
|
||||||
backgroundImage: imageProvider,
|
|
||||||
radius: 25,
|
|
||||||
),
|
|
||||||
placeholder: (context, url) => CircularProgressIndicator(),
|
|
||||||
errorWidget: (context, url, error) => CircleAvatar(
|
|
||||||
child: Icon(Icons.person),
|
|
||||||
backgroundColor: Colors.white,
|
|
||||||
radius: 25,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
SizedBox(height: 16.0),
|
SizedBox(height: 15.v),
|
||||||
Text(state.recipe?['title'], style: CustomTextStyles.titleMediumBlack),
|
_buildTextField(context, state),
|
||||||
SizedBox(height: 8.0),
|
SizedBox(height: 15.v),
|
||||||
Text(
|
_buildCommentSection(context, state),
|
||||||
state.recipe?['description'],
|
],
|
||||||
),
|
),
|
||||||
SizedBox(height: 16.0),
|
)));
|
||||||
Row(
|
}
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
||||||
children: [
|
_buildHeaderRow(BuildContext context, RecipeLoadedState state) {
|
||||||
ElevatedButton(
|
final String name = state.author?['name'];
|
||||||
onPressed: () => Navigator.pushNamed(context, AppRoutes.recipeEditScreen, arguments: state.recipe?['id'].toString()),
|
return Container(
|
||||||
child: Text('Редактировать'),
|
margin: EdgeInsets.symmetric(horizontal: 16.h, vertical: 16.h),
|
||||||
),
|
padding: EdgeInsets.symmetric(
|
||||||
ElevatedButton(
|
horizontal: 24.h,
|
||||||
onPressed: () => context.read<RecipeBloc>().add(DeleteEntry(state.recipe?['id'])),
|
vertical: 12.v,
|
||||||
child: Text('Удалить'),
|
),
|
||||||
),
|
decoration: BoxDecoration(
|
||||||
],
|
color: Colors.white,
|
||||||
)
|
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||||
]),
|
boxShadow: [
|
||||||
)
|
BoxShadow(
|
||||||
],
|
color: Colors.grey.withOpacity(0.5),
|
||||||
|
spreadRadius: 2,
|
||||||
|
blurRadius: 5,
|
||||||
|
offset: Offset(0, 3),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
CustomImageView(
|
||||||
|
imagePath: ImageConstant.imgArrowLeft,
|
||||||
|
onTap: () => NavigatorService.goBack()),
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(top: 1.v),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
child: Text(
|
||||||
|
"$name",
|
||||||
|
style: CustomTextStyles.titleMediumBlack,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
CachedNetworkImage(
|
||||||
|
imageUrl: dotenv.env['STORAGE_URL']! +
|
||||||
|
(state.author?['profile_photo_path'] ?? ''),
|
||||||
|
imageBuilder: (context, imageProvider) => CircleAvatar(
|
||||||
|
backgroundImage: imageProvider,
|
||||||
|
radius: 25,
|
||||||
|
),
|
||||||
|
placeholder: (context, url) => CircularProgressIndicator(),
|
||||||
|
errorWidget: (context, url, error) => CircleAvatar(
|
||||||
|
child: Icon(Icons.person),
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
radius: 25,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
///Handling page based on route
|
_buildRecipeData(BuildContext context, RecipeLoadedState state) {
|
||||||
Widget getCurrentPage(
|
return Container(
|
||||||
BuildContext context,
|
margin: EdgeInsets.only(
|
||||||
String currentRoute,
|
left: 16.h,
|
||||||
) {
|
right: 20.h,
|
||||||
switch (currentRoute) {
|
bottom: 10.h,
|
||||||
case AppRoutes.recipeScreen:
|
),
|
||||||
return RecipeScreen.builder(context);
|
padding: EdgeInsets.all(12.h),
|
||||||
default:
|
decoration: BoxDecoration(
|
||||||
return RecipeScreen();
|
color: Colors.white,
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.grey.withOpacity(0.5),
|
||||||
|
spreadRadius: 2,
|
||||||
|
blurRadius: 5,
|
||||||
|
offset: Offset(0, 3),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
state.recipe?['title'],
|
||||||
|
style: CustomTextStyles.titleMediumBlack,
|
||||||
|
),
|
||||||
|
Spacer(),
|
||||||
|
PopupMenuButton<String>(
|
||||||
|
onSelected: (value) => tapMenu(value, context, state),
|
||||||
|
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
value: 'edit',
|
||||||
|
child: Text('Редактировать'),
|
||||||
|
),
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
value: 'delete',
|
||||||
|
child: Text('Удалить'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
SizedBox(height: 8.0),
|
||||||
|
_buildImage(state),
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
Text(
|
||||||
|
state.recipe?['description'],
|
||||||
|
style: CustomTextStyles.bodyMediumBluegray800,
|
||||||
|
),
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.topLeft,
|
||||||
|
child: Text(
|
||||||
|
DateFormat('dd.MM.yyyy')
|
||||||
|
.format(DateTime.parse(state.recipe?['updated_at'])),
|
||||||
|
style: theme.textTheme.bodyMedium,
|
||||||
|
)),
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
_buildTags(state.tags),
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
Row(children: [
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(left: 24),
|
||||||
|
child: Row(children: [
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(right: 8),
|
||||||
|
child: Icon(Icons.favorite_outline),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
"Нравится",
|
||||||
|
style: CustomTextStyles.titleMediumSemiBold,
|
||||||
|
)
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
Spacer(),
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(right: 24),
|
||||||
|
child: Row(children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 8),
|
||||||
|
child: Icon(Icons.share_outlined),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
"Поделиться",
|
||||||
|
style: CustomTextStyles.titleMediumSemiBold,
|
||||||
|
)
|
||||||
|
]))
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_buildTags(List<dynamic>? tags) {
|
||||||
|
return Wrap(
|
||||||
|
spacing: 8.0,
|
||||||
|
runSpacing: 4.0,
|
||||||
|
children: tags!.map((tag) {
|
||||||
|
return Chip(
|
||||||
|
label: Text(tag['name']),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_buildImage(RecipeLoadedState state) {
|
||||||
|
return CachedNetworkImage(
|
||||||
|
imageUrl: dotenv.env['STORAGE_URL']! + (state.recipe?['image'] ?? ''),
|
||||||
|
imageBuilder: (context, imageProvider) => Stack(
|
||||||
|
children: [
|
||||||
|
ClipRRect(
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(8.0)),
|
||||||
|
child: Image(
|
||||||
|
image: imageProvider,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
bottom: 0,
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
child: Container(
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 48.0),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.remove_red_eye,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
SizedBox(width: 4.0),
|
||||||
|
Text(
|
||||||
|
'24',
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.favorite,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
SizedBox(width: 4.0),
|
||||||
|
Text(
|
||||||
|
'24',
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 48.0),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
Icons.comment_outlined,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
SizedBox(width: 4.0),
|
||||||
|
Text(
|
||||||
|
'${state.comments?.length}',
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
placeholder: (context, url) => CircularProgressIndicator(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tapMenu(String value, BuildContext context, RecipeLoadedState state) {
|
||||||
|
if (value == 'edit') {
|
||||||
|
Navigator.pushNamed(
|
||||||
|
context,
|
||||||
|
AppRoutes.recipeEditScreen,
|
||||||
|
arguments: state.recipe?['id'].toString(),
|
||||||
|
);
|
||||||
|
} else if (value == 'delete') {
|
||||||
|
context.read<RecipeBloc>().add(DeleteEntry(state.recipe?['id']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_buildTextField(BuildContext context, RecipeLoadedState state) {
|
||||||
|
return Container(
|
||||||
|
margin: EdgeInsets.only(
|
||||||
|
left: 16.h,
|
||||||
|
right: 20.h,
|
||||||
|
bottom: 10.h,
|
||||||
|
),
|
||||||
|
padding: EdgeInsets.all(12.h),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.grey.withOpacity(0.5),
|
||||||
|
spreadRadius: 2,
|
||||||
|
blurRadius: 5,
|
||||||
|
offset: Offset(0, 3),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Column(
|
||||||
|
children: [
|
||||||
|
CustomTextFormField(
|
||||||
|
controller: state.commentController,
|
||||||
|
maxLines: 4,
|
||||||
|
),
|
||||||
|
SizedBox(height: 15.h),
|
||||||
|
CustomOutlinedButton(
|
||||||
|
text: "Оставить отзыв",
|
||||||
|
margin: EdgeInsets.only(bottom: 5),
|
||||||
|
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.transparent,
|
||||||
|
),
|
||||||
|
onPressed: () => context
|
||||||
|
.read<RecipeBloc>()
|
||||||
|
.add(CreateComment(state.commentController!.text)),
|
||||||
|
// Установите прозрачный фон
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_buildCommentSection(BuildContext context, RecipeLoadedState state) {
|
||||||
|
if (state.comments != null && state.comments!.isNotEmpty) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
for (int i = 0; i < state.comments!.length; i++)
|
||||||
|
Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
CommentWidget(state.comments![i]),
|
||||||
|
SizedBox(height: 10.0), // Separator
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Return a message or placeholder widget when there are no comments
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Center(
|
||||||
|
child: Text('No comments available'),
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
height: 20,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,4 +410,48 @@ class RecipeScreen extends StatelessWidget {
|
|||||||
onTapArrowleftone(BuildContext context) {
|
onTapArrowleftone(BuildContext context) {
|
||||||
NavigatorService.goBack();
|
NavigatorService.goBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildStep(BuildContext context, RecipeLoadedState state, int i) {
|
||||||
|
return Container(
|
||||||
|
margin: EdgeInsets.only(
|
||||||
|
left: 16.h,
|
||||||
|
right: 16.h,
|
||||||
|
bottom: 10.h,
|
||||||
|
),
|
||||||
|
padding: EdgeInsets.all(12.h),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.grey.withOpacity(0.5),
|
||||||
|
spreadRadius: 2,
|
||||||
|
blurRadius: 5,
|
||||||
|
offset: Offset(0, 3),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Column(mainAxisSize: MainAxisSize.min, children: [
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: Text(
|
||||||
|
"Шаг ${i + 1}",
|
||||||
|
style: CustomTextStyles.titleMediumSemiBold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
CachedNetworkImage(
|
||||||
|
imageUrl: dotenv.env['STORAGE_URL']! + (state.steps?[i]['image']),
|
||||||
|
width: double
|
||||||
|
.infinity, // Установите ширину равной ширине родительского элемента
|
||||||
|
height: 200.0, // Задайте постоянную высоту элемента
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
placeholder: (context, url) => CircularProgressIndicator(),
|
||||||
|
errorWidget: (context, url, error) => Icon(Icons.error),
|
||||||
|
),
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
Text(state.steps?[i]['description'])
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
// ignore_for_file: must_be_immutable
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||||
|
import 'package:eatvio_app/core/app_export.dart';
|
||||||
|
import 'package:eatvio_app/presentation/feed/blog_post_screen/models/comment_model.dart';
|
||||||
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
|
|
||||||
|
class CommentWidget extends StatelessWidget {
|
||||||
|
CommentWidget(this.commentModelObj, {Key? key})
|
||||||
|
: super(
|
||||||
|
key: key,
|
||||||
|
);
|
||||||
|
|
||||||
|
CommentModel commentModelObj;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
margin: EdgeInsets.only(
|
||||||
|
left: 16.h,
|
||||||
|
right: 20.h,
|
||||||
|
bottom: 10.h,
|
||||||
|
),
|
||||||
|
padding: EdgeInsets.all(12.h),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.grey.withOpacity(0.5),
|
||||||
|
spreadRadius: 2,
|
||||||
|
blurRadius: 5,
|
||||||
|
offset: Offset(0, 3),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment
|
||||||
|
.spaceBetween, // Move the main axis alignment to space between
|
||||||
|
crossAxisAlignment:
|
||||||
|
CrossAxisAlignment.center, // Center the items vertically
|
||||||
|
children: [
|
||||||
|
CachedNetworkImage(
|
||||||
|
imageUrl: dotenv.env['STORAGE_URL']! + commentModelObj.userImage!,
|
||||||
|
imageBuilder: (context, imageProvider) => CircleAvatar(
|
||||||
|
backgroundImage: imageProvider,
|
||||||
|
radius: 25,
|
||||||
|
),
|
||||||
|
placeholder: (context, url) => CircularProgressIndicator(),
|
||||||
|
errorWidget: (context, url, error) => CircleAvatar(
|
||||||
|
child: Icon(Icons.person),
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
radius: 25,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.only(
|
||||||
|
left: 12.h,
|
||||||
|
top: 2.v,
|
||||||
|
bottom: 11.v,
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: 227.h,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
commentModelObj.username!.length <= 15
|
||||||
|
? commentModelObj.username!
|
||||||
|
: commentModelObj.username!.substring(0, 15) +
|
||||||
|
'...',
|
||||||
|
style: theme.textTheme.titleMedium,
|
||||||
|
),
|
||||||
|
Spacer(),
|
||||||
|
Padding(
|
||||||
|
padding: EdgeInsets.only(left: 6.h),
|
||||||
|
child: Text(
|
||||||
|
commentModelObj.dateText!,
|
||||||
|
style: theme.textTheme.bodyMedium,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
SizedBox(height: 6.v),
|
||||||
|
Text(
|
||||||
|
commentModelObj.greetingText!,
|
||||||
|
style: CustomTextStyles.bodyMediumBluegray800,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
CustomImageView(
|
||||||
|
imagePath: ImageConstant.imgSend,
|
||||||
|
height: 30.v,
|
||||||
|
width: 30.h,
|
||||||
|
margin: EdgeInsets.only(left: 5)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,8 @@ class CustomTextFormField extends StatelessWidget {
|
|||||||
this.keyboardType,
|
this.keyboardType,
|
||||||
this.onFieldSubmitted,
|
this.onFieldSubmitted,
|
||||||
this.onSaved,
|
this.onSaved,
|
||||||
|
this.initialValue,
|
||||||
|
this.onChanged,
|
||||||
}) : super(
|
}) : super(
|
||||||
key: key,
|
key: key,
|
||||||
);
|
);
|
||||||
@@ -57,8 +59,10 @@ class CustomTextFormField extends StatelessWidget {
|
|||||||
final bool? filled;
|
final bool? filled;
|
||||||
final TextInputType? keyboardType;
|
final TextInputType? keyboardType;
|
||||||
final FormFieldValidator<String>? validator;
|
final FormFieldValidator<String>? validator;
|
||||||
|
final String? initialValue;
|
||||||
final Function(String)? onFieldSubmitted;
|
final Function(String)? onFieldSubmitted;
|
||||||
final void Function(String?)? onSaved;
|
final void Function(String?)? onSaved;
|
||||||
|
final void Function(String?)? onChanged;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -76,6 +80,7 @@ class CustomTextFormField extends StatelessWidget {
|
|||||||
textInputAction: textInputAction,
|
textInputAction: textInputAction,
|
||||||
maxLines: maxLines ?? 1,
|
maxLines: maxLines ?? 1,
|
||||||
onFieldSubmitted: onFieldSubmitted,
|
onFieldSubmitted: onFieldSubmitted,
|
||||||
|
onChanged: onChanged,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: hintText ?? "",
|
hintText: hintText ?? "",
|
||||||
hintStyle: hintStyle ?? theme.textTheme.bodyLarge,
|
hintStyle: hintStyle ?? theme.textTheme.bodyLarge,
|
||||||
@@ -116,6 +121,7 @@ class CustomTextFormField extends StatelessWidget {
|
|||||||
validator: validator,
|
validator: validator,
|
||||||
onSaved: onSaved,
|
onSaved: onSaved,
|
||||||
inputFormatters: inputFormatters,
|
inputFormatters: inputFormatters,
|
||||||
|
initialValue: initialValue,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -129,6 +135,7 @@ class CustomTextFormField extends StatelessWidget {
|
|||||||
obscureText: obscureText!,
|
obscureText: obscureText!,
|
||||||
textInputAction: textInputAction,
|
textInputAction: textInputAction,
|
||||||
maxLines: maxLines ?? 1,
|
maxLines: maxLines ?? 1,
|
||||||
|
initialValue: initialValue,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: hintText ?? "",
|
hintText: hintText ?? "",
|
||||||
hintStyle: hintStyle ?? theme.textTheme.bodyLarge,
|
hintStyle: hintStyle ?? theme.textTheme.bodyLarge,
|
||||||
|
|||||||
Reference in New Issue
Block a user