Merge pull request 'fix: analyzer fix' (#1027) from misha/eatvio_app:post_creation_with_images into post_creation_with_images

Reviewed-on: eatvio/eatvio_app#1027
This commit is contained in:
2026-08-05 12:34:27 +00:00

View File

@@ -26,11 +26,7 @@ class BlogPostScreen extends StatefulWidget {
final int id; final int id;
final int? highlightedCommentId; final int? highlightedCommentId;
const BlogPostScreen({ const BlogPostScreen({super.key, required this.id, this.highlightedCommentId});
super.key,
required this.id,
this.highlightedCommentId,
});
@override @override
State<BlogPostScreen> createState() => _BlogPostScreenState(); State<BlogPostScreen> createState() => _BlogPostScreenState();
@@ -49,10 +45,7 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
} }
void _openGallery(List<String> imageUrls, int index, {Object? heroTag}) { void _openGallery(List<String> imageUrls, int index, {Object? heroTag}) {
context.pushTransparentRoute( context.pushTransparentRoute(rootNavigator: true, PhotoViewScreen(imageUrls: imageUrls, index: index, heroTag: heroTag));
rootNavigator: true,
PhotoViewScreen(imageUrls: imageUrls, index: index, heroTag: heroTag),
);
} }
@override @override
@@ -60,8 +53,7 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
return BlocProvider( return BlocProvider(
create: (context) => sl<BlogPostCubit>()..getBlogPost(widget.id), create: (context) => sl<BlogPostCubit>()..getBlogPost(widget.id),
child: BlocProvider<CommentsCubit>( child: BlocProvider<CommentsCubit>(
create: (BuildContext context) => commentsCubit create: (BuildContext context) => commentsCubit..getComments(widget.id.toString(), CommentSourceType.blogPost, true),
..getComments(widget.id.toString(), CommentSourceType.blogPost, true),
child: BlocBuilder<BlogPostCubit, BlogPostState>( child: BlocBuilder<BlogPostCubit, BlogPostState>(
builder: (context, blogPostState) { builder: (context, blogPostState) {
return BlocConsumer<CommentsCubit, CommentsState>( return BlocConsumer<CommentsCubit, CommentsState>(
@@ -89,23 +81,15 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
body: const Loader(), body: const Loader(),
); );
} }
final bool isLiked = final bool isLiked = blogPostState.blogPostModel?.wasLikedByMe ?? false;
blogPostState.blogPostModel?.wasLikedByMe ?? false; final int totalLikes = blogPostState.blogPostModel?.totalLikes ?? 0;
final int totalLikes =
blogPostState.blogPostModel?.totalLikes ?? 0;
return Scaffold( return Scaffold(
resizeToAvoidBottomInset: true, resizeToAvoidBottomInset: true,
bottomSheet: Container( bottomSheet: Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom + 8),
bottom: MediaQuery.of(context).padding.bottom + 8,
),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
border: Border( border: Border(top: BorderSide(color: Colors.black.withValues(alpha: 0.1))),
top: BorderSide(
color: Colors.black.withValues(alpha: 0.1),
),
),
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 0), padding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
@@ -123,17 +107,10 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
FocusManager.instance.primaryFocus?.unfocus(); FocusManager.instance.primaryFocus?.unfocus();
}, },
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(color: appTheme.blueA400, shape: BoxShape.circle),
color: appTheme.blueA400,
shape: BoxShape.circle,
),
height: 32, height: 32,
width: 32, width: 32,
child: const Icon( child: const Icon(Icons.close_rounded, size: 18, color: Colors.white),
Icons.close_rounded,
size: 18,
color: Colors.white,
),
), ),
), ),
if (replyId != null) const SizedBox(width: 8), if (replyId != null) const SizedBox(width: 8),
@@ -141,8 +118,7 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
child: ConstrainedBox( child: ConstrainedBox(
constraints: const BoxConstraints(minHeight: 52), constraints: const BoxConstraints(minHeight: 52),
child: TextFormField( child: TextFormField(
textCapitalization: textCapitalization: TextCapitalization.sentences,
TextCapitalization.sentences,
onChanged: (_) { onChanged: (_) {
setState(() {}); setState(() {});
}, },
@@ -150,48 +126,26 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
maxLines: 5, maxLines: 5,
minLines: 1, minLines: 1,
keyboardType: TextInputType.multiline, keyboardType: TextInputType.multiline,
style: const TextStyle( style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w400, color: Colors.black, height: 1.2),
fontSize: 16,
fontWeight: FontWeight.w400,
color: Colors.black,
height: 1.2,
),
decoration: InputDecoration( decoration: InputDecoration(
isDense: false, isDense: false,
// убираем true, чтобы padding учитывался корректно // убираем true, чтобы padding учитывался корректно
contentPadding: const EdgeInsets.symmetric( contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
horizontal: 16,
vertical: 16,
),
// вертикальный паддинг увеличен // вертикальный паддинг увеличен
hintText: S.of(context).comment_hint, hintText: S.of(context).comment_hint,
hintStyle: const TextStyle( hintStyle: const TextStyle(fontSize: 16, fontWeight: FontWeight.w400, height: 1.2, color: Color(0xFFAEAEB2)),
fontSize: 16,
fontWeight: FontWeight.w400,
height: 1.2,
color: Color(0xFFAEAEB2),
),
filled: true, filled: true,
border: OutlineInputBorder( border: OutlineInputBorder(
borderRadius: BorderRadius.circular(16), borderRadius: BorderRadius.circular(16),
borderSide: const BorderSide( borderSide: const BorderSide(color: Color(0xFFD1D1D6), width: 1),
color: Color(0xFFD1D1D6),
width: 1,
),
), ),
enabledBorder: OutlineInputBorder( enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(16), borderRadius: BorderRadius.circular(16),
borderSide: const BorderSide( borderSide: const BorderSide(color: Color(0xFFD1D1D6), width: 1),
color: Color(0xFFD1D1D6),
width: 1,
),
), ),
focusedBorder: OutlineInputBorder( focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(16), borderRadius: BorderRadius.circular(16),
borderSide: const BorderSide( borderSide: const BorderSide(color: Color(0xFFD1D1D6), width: 1),
color: Color(0xFFD1D1D6),
width: 1,
),
), ),
), ),
), ),
@@ -209,10 +163,7 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
); );
if (!context.mounted) return; if (!context.mounted) return;
if (isSent) if (isSent) context.read<FeedCubit>().incrementCommentsState(widget.id);
context
.read<FeedCubit>()
.incrementCommentsState(widget.id);
context.read<CommentsCubit>().setReplyId(null); context.read<CommentsCubit>().setReplyId(null);
setState(() { setState(() {
@@ -223,19 +174,10 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
} }
}, },
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(color: textEditingController.text.length > 2 ? appTheme.blueA400 : Colors.grey, shape: BoxShape.circle),
color: textEditingController.text.length > 2
? appTheme.blueA400
: Colors.grey,
shape: BoxShape.circle,
),
height: 32, height: 32,
width: 32, width: 32,
child: const Icon( child: const Icon(Icons.send_rounded, size: 18, color: Colors.white),
Icons.send_rounded,
size: 18,
color: Colors.white,
),
), ),
), ),
], ],
@@ -255,33 +197,23 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
), ),
actions: [ actions: [
CustomPopup( CustomPopup(
isAuthor: isAuthor: blogPostState.blogPostModel?.author.authorIsMe ?? false,
blogPostState.blogPostModel?.author.authorIsMe ??
false,
complainedContentType: ComplainedContent.posts, complainedContentType: ComplainedContent.posts,
path: 'blog_post/${(widget.id)}', path: 'blog_post/${(widget.id)}',
id: widget.id, id: widget.id,
feedBlogPostModel: blogPostState.blogPostModel, feedBlogPostModel: blogPostState.blogPostModel,
userSlug: userSlug: blogPostState.blogPostModel?.author.authorSlug ?? '',
blogPostState.blogPostModel?.author.authorSlug ??
'',
), ),
const SizedBox(width: 16), const SizedBox(width: 16),
], ],
), ),
body: SingleChildScrollView( body: SingleChildScrollView(
padding: EdgeInsets.only( padding: EdgeInsets.only(bottom: 160 + MediaQuery.of(context).padding.bottom), // поле комментария (52-200) + padding (12+12+56) + safe area
bottom: 160 + MediaQuery.of(context).padding.bottom,
), // поле комментария (52-200) + padding (12+12+56) + safe area
physics: const BouncingScrollPhysics(), physics: const BouncingScrollPhysics(),
child: Column( child: Column(
children: [ children: [
GestureDetector( GestureDetector(
onTap: () => GoRouter.of(context).pushNamed( onTap: () => GoRouter.of(context).pushNamed('profileScreen', extra: blogPostState.blogPostModel?.author.authorSlug),
'profileScreen',
extra:
blogPostState.blogPostModel?.author.authorSlug,
),
child: Ink( child: Ink(
padding: const EdgeInsets.symmetric(horizontal: 16), padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row( child: Row(
@@ -290,46 +222,21 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
children: [ children: [
CircleAvatar( CircleAvatar(
radius: 16, radius: 16,
foregroundImage: NetworkImage( foregroundImage: NetworkImage(sl<AppConfig>().baseUrl + (blogPostState.blogPostModel?.author.authorProfileIcon ?? '')),
sl<AppConfig>().baseUrl + backgroundImage: const AssetImage('assets/images/no_avatar.png'),
(blogPostState
.blogPostModel
?.author
.authorProfileIcon ??
''),
),
backgroundImage: const AssetImage(
'assets/images/no_avatar.png',
),
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
Column( Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
blogPostState blogPostState.blogPostModel?.author.authorName ?? '',
.blogPostModel style: const TextStyle(color: Colors.black, fontSize: 14, fontWeight: FontWeight.w400, height: 1),
?.author
.authorName ??
'',
style: const TextStyle(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.w400,
height: 1,
),
), ),
const SizedBox(height: 2), const SizedBox(height: 2),
Text( Text(
(blogPostState.blogPostModel?.createdAt ?? (blogPostState.blogPostModel?.createdAt ?? DateTime.now()).format('dd MMMM', 'ru'),
DateTime.now()) style: TextStyle(color: Colors.grey.shade600, fontSize: 12, fontWeight: FontWeight.w400, height: 1),
.format('dd MMMM', 'ru'),
style: TextStyle(
color: Colors.grey.shade600,
fontSize: 12,
fontWeight: FontWeight.w400,
height: 1,
),
), ),
], ],
), ),
@@ -337,20 +244,10 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
), ),
), ),
), ),
if (blogPostState if (blogPostState.blogPostModel?.description.isNotEmpty ?? false)
.blogPostModel
?.description
.isNotEmpty ??
false)
Padding( Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
horizontal: 16, child: MarkdownHtmlWidget(markdownText: blogPostState.blogPostModel!.description),
vertical: 8,
),
child: MarkdownHtmlWidget(
markdownText:
blogPostState.blogPostModel!.description,
),
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
Builder( Builder(
@@ -359,31 +256,16 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
if (post == null) { if (post == null) {
return const SizedBox.shrink(); return const SizedBox.shrink();
} }
final imageUrl = PostFeedMapper.resolveMediaUrl( final imageUrl = PostFeedMapper.resolveMediaUrl(post.image);
post.image,
);
final embedUrl = post.videoEmbedUrl?.trim(); final embedUrl = post.videoEmbedUrl?.trim();
return BlogPostMediaContent( return BlogPostMediaContent(
galleryImages: post.images, galleryImages: post.images,
imageUrl: imageUrl, imageUrl: imageUrl,
videoEmbedUrl: videoEmbedUrl: embedUrl != null && embedUrl.isNotEmpty ? embedUrl : null,
embedUrl != null && embedUrl.isNotEmpty videoUrlThumb: post.videoUrlThumb != null ? PostFeedMapper.resolveMediaUrl(post.videoUrlThumb) : null,
? embedUrl
: null,
videoUrlThumb: post.videoUrlThumb != null
? PostFeedMapper.resolveMediaUrl(
post.videoUrlThumb,
)
: null,
currentGalleryIndex: currentGalleryIndex, currentGalleryIndex: currentGalleryIndex,
heroTag: 'blog-post-screen-${post.id}-cover', heroTag: 'blog-post-screen-${post.id}-cover',
onOpenGallery: (urls, index) => _openGallery( onOpenGallery: (urls, index) => _openGallery(urls, index, heroTag: urls.length == 1 ? 'blog-post-screen-${post.id}-cover' : null),
urls,
index,
heroTag: urls.length == 1
? 'blog-post-screen-${post.id}-cover'
: null,
),
onGalleryChanged: (index) { onGalleryChanged: (index) {
setState(() { setState(() {
currentGalleryIndex = index; currentGalleryIndex = index;
@@ -393,43 +275,22 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
}, },
), ),
Padding( Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
horizontal: 16,
vertical: 12,
),
child: Row( child: Row(
children: [ children: [
_iconButton( _iconButton(
icon: isLiked icon: isLiked ? Icons.favorite_rounded : Icons.favorite_border_rounded,
? Icons.favorite_rounded
: Icons.favorite_border_rounded,
text: totalLikes.toString(), text: totalLikes.toString(),
iconColor: isLiked iconColor: isLiked ? Colors.red.withValues(alpha: 0.8) : null,
? Colors.red.withValues(alpha: 0.8) backgroundColor: isLiked ? Colors.red.withValues(alpha: 0.1) : null,
: null, textColor: isLiked ? Colors.red.withValues(alpha: 0.8) : null,
backgroundColor: isLiked
? Colors.red.withValues(alpha: 0.1)
: null,
textColor: isLiked
? Colors.red.withValues(alpha: 0.8)
: null,
onTap: () async { onTap: () async {
await context await context.read<BlogPostCubit>().toggleLike();
.read<BlogPostCubit>()
.toggleLike();
// ignore: use_build_context_synchronously // ignore: use_build_context_synchronously
final updated = context final updated = context.read<BlogPostCubit>().state.blogPostModel;
.read<BlogPostCubit>()
.state
.blogPostModel;
if (updated != null) { if (updated != null) {
// ignore: use_build_context_synchronously // ignore: use_build_context_synchronously
context context.read<FeedCubit>().updateFeedBlogPostList(updated, updated.wasLikedByMe);
.read<FeedCubit>()
.updateFeedBlogPostList(
updated,
updated.wasLikedByMe,
);
} }
}, },
), ),
@@ -437,36 +298,21 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
_iconButton( _iconButton(
icon: Icons.reply_rounded, icon: Icons.reply_rounded,
onTap: () { onTap: () {
final box = final box = context.findRenderObject() as RenderBox?;
context.findRenderObject() as RenderBox?;
SharePlus.instance.share( SharePlus.instance.share(
ShareParams( ShareParams(
uri: Uri.parse( uri: Uri.parse('${sl<AppConfig>().baseUrl}/ru/blog_post/${widget.id}'),
'${sl<AppConfig>().baseUrl}/ru/blog_post/${widget.id}', sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
),
sharePositionOrigin:
box!.localToGlobal(Offset.zero) &
box.size,
), ),
); );
}, },
), ),
const Spacer(), const Spacer(),
Icon( Icon(Icons.visibility_rounded, size: 16, color: appTheme.gray500),
Icons.visibility_rounded,
size: 16,
color: appTheme.gray500,
),
const SizedBox(width: 4), const SizedBox(width: 4),
Text( Text(
blogPostState.blogPostModel?.totalViews blogPostState.blogPostModel?.totalViews.toString() ?? '',
.toString() ?? style: TextStyle(fontSize: 12, color: appTheme.gray500, fontWeight: FontWeight.w400),
'',
style: TextStyle(
fontSize: 12,
color: appTheme.gray500,
fontWeight: FontWeight.w400,
),
), ),
], ],
), ),
@@ -474,10 +320,7 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
Container( Container(
width: MediaQuery.of(context).size.width - 32, width: MediaQuery.of(context).size.width - 32,
height: 0.4, height: 0.4,
decoration: BoxDecoration( decoration: BoxDecoration(color: Colors.black.withValues(alpha: 0.2), borderRadius: BorderRadius.circular(16)),
color: Colors.black.withValues(alpha: 0.2),
borderRadius: BorderRadius.circular(16),
),
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
Container( Container(
@@ -485,11 +328,7 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Text( child: Text(
'${blogPostState.blogPostModel?.totalComments} КОММЕНТАРИЕВ', '${blogPostState.blogPostModel?.totalComments} КОММЕНТАРИЕВ',
style: TextStyle( style: TextStyle(fontSize: 12, color: appTheme.gray500, fontWeight: FontWeight.w400),
fontSize: 12,
color: appTheme.gray500,
fontWeight: FontWeight.w400,
),
), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
@@ -514,23 +353,13 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
); );
} }
InkWell _iconButton({ InkWell _iconButton({required IconData icon, String? text, Function()? onTap, Color? iconColor, Color? backgroundColor, Color? textColor}) {
required IconData icon,
String? text,
Function()? onTap,
Color? iconColor,
Color? backgroundColor,
Color? textColor,
}) {
return InkWell( return InkWell(
onTap: onTap ?? () {}, onTap: onTap ?? () {},
borderRadius: BorderRadius.circular(16), borderRadius: BorderRadius.circular(16),
child: Ink( child: Ink(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4), padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
decoration: BoxDecoration( decoration: BoxDecoration(color: backgroundColor ?? appTheme.gray100, borderRadius: BorderRadius.circular(16)),
color: backgroundColor ?? appTheme.gray100,
borderRadius: BorderRadius.circular(16),
),
height: 32, height: 32,
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
@@ -540,10 +369,7 @@ class _BlogPostScreenState extends State<BlogPostScreen> {
if (text != null) if (text != null)
Text( Text(
text, text,
style: TextStyle( style: TextStyle(color: textColor ?? appTheme.gray600, fontWeight: FontWeight.w500),
color: textColor ?? appTheme.gray600,
fontWeight: FontWeight.w500,
),
), ),
], ],
), ),