Merge branch 'main' into main

This commit is contained in:
2024-06-04 10:03:16 +00:00
18 changed files with 1320 additions and 159 deletions

View File

@@ -36,9 +36,11 @@ class BlogPostCreateBloc
blog_postModelObj: currentState.blog_postModelObj,
title: currentState.title,
description: currentState.description,
youtube_url: currentState.youtube_url));
youtube_url: currentState.youtube_url,
token: currentState.token));
} else {
emit(BlogPostCreateLoadedState(
token: token,
title: TextEditingController(),
description: TextEditingController(),
youtube_url: TextEditingController()));
@@ -71,7 +73,8 @@ class BlogPostCreateBloc
String? description,
) async {
String url = '${dotenv.env['SERVER_ROOT']!}/feed/create';
final box = await Hive.openBox('token');
final token = box.get('token');
final Map<String, dynamic> credentials = {
'title': title,
'description': description,
@@ -83,6 +86,7 @@ class BlogPostCreateBloc
Uri.parse(url),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer $token',
},
body: json.encode(credentials),
encoding: utf8,

View File

@@ -23,26 +23,32 @@ class BlogPostCreateState extends Equatable {
class BlogPostCreateLoadedState extends BlogPostCreateState {
BlogPostCreateLoadedState(
{this.blog_postModelObj, this.title, this.description, this.youtube_url});
{this.token,
this.blog_postModelObj,
this.title,
this.description,
this.youtube_url});
BlogPostCreateModel? blog_postModelObj;
TextEditingController? title;
TextEditingController? description;
TextEditingController? youtube_url;
String? token;
@override
List<Object?> get props =>
[blog_postModelObj, title, description, youtube_url];
BlogPostCreateLoadedState copyWith({
BlogPostCreateModel? blog_postModelObj,
TextEditingController? title,
TextEditingController? description,
TextEditingController? youtube_url,
}) {
BlogPostCreateLoadedState copyWith(
{BlogPostCreateModel? blog_postModelObj,
TextEditingController? title,
TextEditingController? description,
TextEditingController? youtube_url,
String? token}) {
return BlogPostCreateLoadedState(
blog_postModelObj: blog_postModelObj ?? this.blog_postModelObj,
title: title ?? this.title,
description: description ?? this.description,
youtube_url: youtube_url ?? this.youtube_url,
token: token ?? this.token,
);
}
}

View File

@@ -3,6 +3,8 @@ import 'models/blog_post_create_model.dart';
import 'package:eatvio_app/core/app_export.dart';
import 'package:flutter/material.dart';
import 'package:eatvio_app/widgets/custom_bottom_bar.dart';
import 'package:eatvio_app/widgets/custom_text_form_field.dart';
import 'package:eatvio_app/widgets/custom_outlined_button.dart';
class BlogPostCreateScreen extends StatelessWidget {
const BlogPostCreateScreen({Key? key}) : super(key: key);
@@ -44,61 +46,123 @@ class BlogPostCreateScreen extends StatelessWidget {
child: Scaffold(
resizeToAvoidBottomInset: false,
body: Container(
width: double.maxFinite,
decoration: AppDecoration.fillGray,
child: ListView(children: [
SizedBox(height: 30.v),
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),
width: double.maxFinite,
decoration: AppDecoration.fillGray,
child: ListView(children: [
SizedBox(height: 30.v),
Container(
margin: EdgeInsets.only(
left: 16.h,
right: 20.h,
bottom: 10.h,
),
],
),
child: Column(mainAxisSize: MainAxisSize.min, children: [
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.youtube_url,
decoration: InputDecoration(labelText: 'Ссылка'),
),
SizedBox(height: 16.0),
// Здесь нужно добавить виджет для загрузки картинки
ElevatedButton(
onPressed: () => context
.read<BlogPostCreateBloc>()
.add(CreateBlogPost()),
child: Text('Создать'),
)
]),
)
]),
),
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: <Widget>[
Text("Заголовок новости",
style: theme.textTheme.bodyLarge),
CustomTextFormField(
controller: state.title,
validator: _validateTitle,
),
SizedBox(height: 8.0),
Text("Ссылка на YouTube",
style: theme.textTheme.bodyLarge),
CustomTextFormField(
controller: state.youtube_url,
validator: _validateYouTubeLink,
),
SizedBox(height: 8.0),
Text("Описание", style: theme.textTheme.bodyLarge),
CustomTextFormField(
controller: state.description,
validator: _validateDescription,
maxLines: 6,
),
SizedBox(height: 16.0),
// Add widget for image upload here
CustomOutlinedButton(
onPressed: () => _submitForm(
context,
state.title!.text,
state.description!.text,
state.youtube_url!.text),
buttonStyle:
CustomButtonStyles.outlinePrimaryTL15,
text: 'Создать',
),
],
),
]))
])),
bottomNavigationBar: _buildBottomBar(context)));
}
}
_submitForm(
BuildContext context, String title, String description, String youtubeURL) {
String? titleError = _validateTitle(title);
String? descriptionError = _validateDescription(description);
String? youtubeURLError = _validateYouTubeLink(youtubeURL);
if (titleError != null ||
descriptionError != null ||
youtubeURLError != null) {
// Display error messages or handle invalid input as needed
// For example, show a snackbar with the error message
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(titleError ?? descriptionError ?? youtubeURLError!)),
);
} else {
// Proceed with form submission
context.read<BlogPostCreateBloc>().add(CreateBlogPost());
}
}
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);
}
_buildBottomBar(BuildContext context) {
return CustomBottomBar(onChanged: (BottomBarEnum type) {});
}

View File

@@ -80,7 +80,6 @@ class BlogPostBloc extends Bloc<BlogPostEvent, BlogPostState> {
// Отправляем данные по HTTP маршруту и ждем ответ
var response = await _sendCommentData(
currentState.token, event.body, currentState.blog_post?['id']);
if (response.statusCode == 200) {
var updatedComments = fillCommentList(
await _fetchComments(currentState.blog_post?['id']));
@@ -159,7 +158,6 @@ class BlogPostBloc extends Bloc<BlogPostEvent, BlogPostState> {
List<CommentModel> fillCommentList(List<dynamic> comments) {
List<CommentModel> list = [];
for (int i = 0; i < comments.length; i++) {
print(comments[i]);
list.add(CommentModel(
id: comments[i]['id'].toString(),
userImage: comments[i]['profile_photo_path'],
@@ -175,6 +173,7 @@ class BlogPostBloc extends Bloc<BlogPostEvent, BlogPostState> {
String? token, String body, int id) async {
String url = dotenv.env['SERVER_ROOT']! + '/feed/createComment/$id';
final Map<String, dynamic> credentials = {
'id': id,
'body': body,
};

View File

@@ -54,7 +54,7 @@ class FeedScreen extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SizedBox(height: 20),
_buildSearch(),
_buildSearch(context),
SizedBox(height: 20),
_buildMenu(context, state),
SizedBox(height: 20),
@@ -69,7 +69,7 @@ class FeedScreen extends StatelessWidget {
);
}
_buildSearch() {
_buildSearch(BuildContext context) {
return Container(
margin: EdgeInsets.only(bottom: 10),
decoration: BoxDecoration(
@@ -106,6 +106,10 @@ class FeedScreen extends StatelessWidget {
flex: 1,
child: CustomOutlinedButton(
text: "+",
onPressed: () => Navigator.pushNamed(
context,
AppRoutes.blogPostCreateScreen,
),
buttonStyle: CustomButtonStyles.outlinePrimaryTL15,
),
),