forked from eatvio/eatvio_app
blog post
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:eatvio_app/features/feed/models/comment_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/comments_cubit/comments_cubit.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/comments_cubit/comments_state.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_cubit.dart';
|
||||
import 'package:eatvio_app/locator_service.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -22,10 +23,15 @@ class BlogPostScreen extends StatefulWidget {
|
||||
class _BlogPostScreenState extends State<BlogPostScreen> {
|
||||
final CommentsCubit commentsCubit = sl<CommentsCubit>();
|
||||
final textEditingController = TextEditingController();
|
||||
int? replyId;
|
||||
late bool isLiked;
|
||||
late int totalLikes;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
commentsCubit.getBlogPostComments(widget.blogPost.id);
|
||||
isLiked = widget.blogPost.wasLikedByMe;
|
||||
totalLikes = widget.blogPost.totalLikes;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -50,8 +56,32 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (replyId != null)
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
replyId = null;
|
||||
textEditingController.clear();
|
||||
});
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: appTheme.blueA400,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
height: 32,
|
||||
width: 32,
|
||||
child: Icon(
|
||||
Icons.close_rounded,
|
||||
size: 18,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (replyId != null) SizedBox(width: 8),
|
||||
SizedBox(
|
||||
width: mediaQueryData.size.width - 64,
|
||||
width: mediaQueryData.size.width - (replyId == null ? 64 : 104),
|
||||
child: TextFormField(
|
||||
onChanged: (_) {
|
||||
setState(() {});
|
||||
@@ -108,9 +138,11 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
|
||||
commentsCubit.sendBlogPostComment(
|
||||
id: widget.blogPost.id,
|
||||
commentText: textEditingController.text,
|
||||
parentCommentId: replyId,
|
||||
);
|
||||
setState(() {
|
||||
textEditingController.clear();
|
||||
replyId = null;
|
||||
});
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
}
|
||||
@@ -205,7 +237,23 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
_iconButton(icon: Icons.favorite_border_rounded, text: widget.blogPost.totalLikes.toString()),
|
||||
_iconButton(
|
||||
icon: Icons.favorite_border_rounded,
|
||||
text: totalLikes.toString(),
|
||||
iconColor: isLiked ? Colors.red.withOpacity(0.8) : null,
|
||||
backgroundColor: isLiked ? Colors.red.withOpacity(0.1) : null,
|
||||
textColor: isLiked ? Colors.red.withOpacity(0.8) : null,
|
||||
onTap: () async {
|
||||
setState(() {
|
||||
isLiked = !isLiked;
|
||||
isLiked ? totalLikes++ : totalLikes--;
|
||||
});
|
||||
isLiked
|
||||
? await context.read<FeedCubit>().likePost(widget.blogPost.id)
|
||||
: await context.read<FeedCubit>().unlikedPost(widget.blogPost.id);
|
||||
await context.read<FeedCubit>().loadFeedBlogPostList();
|
||||
},
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
_iconButton(
|
||||
icon: Icons.reply_rounded,
|
||||
@@ -293,6 +341,10 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
|
||||
_comment(Datum datum, [double radius = 16]) {
|
||||
return Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
decoration: BoxDecoration(
|
||||
color: replyId == datum.id ? appTheme.blueA400.withOpacity(0.1) : Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Row(
|
||||
@@ -337,7 +389,11 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
|
||||
),
|
||||
SizedBox(width: 16),
|
||||
GestureDetector(
|
||||
onTap: () {},
|
||||
onTap: () {
|
||||
setState(() {
|
||||
replyId = datum.id;
|
||||
});
|
||||
},
|
||||
child: Text(
|
||||
'Ответить',
|
||||
style: TextStyle(
|
||||
@@ -358,14 +414,14 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
_iconButton({required IconData icon, String? text, Function()? onTap}) {
|
||||
_iconButton({required IconData icon, String? text, Function()? onTap, Color? iconColor, Color? backgroundColor, Color? textColor}) {
|
||||
return InkWell(
|
||||
onTap: onTap ?? () {},
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Ink(
|
||||
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: appTheme.gray100,
|
||||
color: backgroundColor ?? appTheme.gray100,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
height: 32,
|
||||
@@ -375,14 +431,14 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
|
||||
Icon(
|
||||
icon,
|
||||
size: 20,
|
||||
color: appTheme.gray600,
|
||||
color: iconColor ?? appTheme.gray600,
|
||||
),
|
||||
if (text != null) SizedBox(width: 8),
|
||||
if (text != null)
|
||||
Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
color: appTheme.gray600,
|
||||
color: textColor ?? appTheme.gray600,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user