forked from eatvio/eatvio_app
234 lines
8.7 KiB
Dart
234 lines
8.7 KiB
Dart
//import 'dart:io';
|
|
|
|
import 'package:eatvio_app/core/app_export.dart';
|
|
import 'package:eatvio_app/widgets/custom_drop_down.dart';
|
|
import 'package:eatvio_app/widgets/custom_text_form_field.dart';
|
|
import 'package:image_picker/image_picker.dart';
|
|
import 'package:flutter/material.dart';
|
|
import '../../../../presentation/feed/blog_post_create_screen/bloc/blog_post_create_bloc.dart';
|
|
|
|
class RecipeCreateScreen extends StatelessWidget {
|
|
const RecipeCreateScreen({
|
|
super.key,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
toolbarHeight: 0,
|
|
automaticallyImplyLeading: false,
|
|
),
|
|
backgroundColor: Color.fromARGB(255, 240, 242, 245),
|
|
resizeToAvoidBottomInset: true,
|
|
body: SizedBox(
|
|
width: double.maxFinite,
|
|
child: Column(
|
|
children: [
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
child: Padding(
|
|
padding: EdgeInsets.only(bottom: 5),
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: 24,
|
|
vertical: 12,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius:
|
|
const BorderRadius.all(Radius.circular(8)),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text('Заголовок'),
|
|
SizedBox(height: 8),
|
|
CustomTextFormField(
|
|
validator: _validateTitle,
|
|
fillColor: appTheme.gray50,
|
|
hintText: 'Заголовок',
|
|
),
|
|
SizedBox(height: 16),
|
|
Text('Тип блюда'),
|
|
SizedBox(height: 8),
|
|
CustomDropDown(
|
|
validator: _validateDescription,
|
|
),
|
|
SizedBox(height: 16),
|
|
Text('Изображение'),
|
|
Container(
|
|
height: 128,
|
|
decoration: AppDecoration.fillGray.copyWith(
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
Icons.photo_library,
|
|
color: appTheme.blueGray300,
|
|
),
|
|
SizedBox(width: 8),
|
|
Text(
|
|
"Добавить фото",
|
|
selectionColor: appTheme.blueA400,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(height: 16),
|
|
Text('Время приготовления'),
|
|
SizedBox(height: 8),
|
|
CustomDropDown(
|
|
validator: _validateYouTubeLink,
|
|
),
|
|
SizedBox(height: 16),
|
|
Text('Статус'),
|
|
SizedBox(height: 8),
|
|
CustomDropDown(
|
|
validator: _validateYouTubeLink,
|
|
),
|
|
SizedBox(height: 24),
|
|
CustomTextFormField(
|
|
hintText: 'Введите название продукта',
|
|
validator: _validateYouTubeLink,
|
|
),
|
|
SizedBox(height: 24),
|
|
CustomTextFormField(
|
|
hintText: 'Порция',
|
|
fillColor: appTheme.gray50,
|
|
validator: _validateYouTubeLink,
|
|
),
|
|
SizedBox(height: 8),
|
|
CustomDropDown(
|
|
validator: _validateYouTubeLink,
|
|
),
|
|
SizedBox(height: 8),
|
|
Container(
|
|
height: 48,
|
|
width: MediaQuery.of(context).size.width,
|
|
child: FloatingActionButton.extended(
|
|
highlightElevation: 0,
|
|
elevation: 0,
|
|
focusElevation: 0,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
backgroundColor: appTheme.blueA400,
|
|
onPressed: () {},
|
|
label: Text(
|
|
'+',
|
|
style: theme.textTheme.titleSmall,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 24),
|
|
Text('Описание рецепта'),
|
|
SizedBox(height: 8),
|
|
CustomTextFormField(
|
|
maxLines: 8,
|
|
minLines: 8,
|
|
validator: _validateYouTubeLink,
|
|
),
|
|
SizedBox(height: 80),
|
|
],
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/*_buildAddPhoto(BuildContext context, BlogPostCreateLoadedState state) {
|
|
bool isLoading = state.isLoading;
|
|
return GestureDetector(
|
|
onTap: addImage(context, isLoading),
|
|
child: Stack(
|
|
children: [
|
|
if (state.image == null)
|
|
Container(
|
|
height: 128,
|
|
decoration: AppDecoration.fillGray.copyWith(
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
Icons.photo_library,
|
|
color: appTheme.blueGray300,
|
|
),
|
|
SizedBox(width: 8),
|
|
Text(
|
|
"Добавить фото",
|
|
selectionColor: appTheme.blueA400,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (state.image != null)
|
|
ClipRRect(
|
|
borderRadius: BorderRadius.circular(16),
|
|
child: Image(
|
|
image: FileImage(
|
|
File(state.image!.path),
|
|
),
|
|
),
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}*/
|
|
|
|
addImage(BuildContext context, bool isLoading) {
|
|
if (!isLoading) {
|
|
return () async {
|
|
final picker = ImagePicker();
|
|
XFile? image = await picker.pickImage(source: ImageSource.gallery);
|
|
if (image != null) {
|
|
context.read<BlogPostCreateBloc>().add(UploadImages(image));
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
String? _validateTitle(value) {
|
|
if (value!.isEmpty) {
|
|
return 'Пожалуйста, введите заголовок';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
String? _validateDescription(value) {
|
|
if (value!.isEmpty) {
|
|
return 'Пожалуйста, введите описание';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
String? _validateYouTubeLink(value) {
|
|
if (value!.isEmpty) {
|
|
return 'Пожалуйста, введите ссылку';
|
|
} else if (!_isValidUrl(value)) {
|
|
return 'Пожалуйста, введите корректную ссылку';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
bool _isValidUrl(String url) {
|
|
final RegExp urlRegExp =
|
|
new RegExp(r"^(http|https):\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$");
|
|
return urlRegExp.hasMatch(url);
|
|
}
|