From b8245b00b61977ae2ed89216d83c084554b795f9 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 14 Nov 2024 22:49:17 +0800 Subject: [PATCH] :lipstick: Post item maxWidth --- lib/screens/explore.dart | 6 +++- lib/screens/post/post_detail.dart | 16 ++++++--- lib/widgets/post/post_comment_list.dart | 47 ++++++++++++++++--------- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/lib/screens/explore.dart b/lib/screens/explore.dart index a8ed730..e5a0a94 100644 --- a/lib/screens/explore.dart +++ b/lib/screens/explore.dart @@ -5,6 +5,7 @@ import 'package:gap/gap.dart'; import 'package:go_router/go_router.dart'; import 'package:material_symbols_icons/symbols.dart'; import 'package:provider/provider.dart'; +import 'package:styled_widget/styled_widget.dart'; import 'package:surface/providers/sn_attachment.dart'; import 'package:surface/providers/sn_network.dart'; import 'package:surface/types/post.dart'; @@ -172,7 +173,10 @@ class _ExploreScreenState extends State { onFetchData: _fetchPosts, itemBuilder: (context, idx) { return GestureDetector( - child: PostItem(data: _posts[idx]), + child: Container( + constraints: const BoxConstraints(maxWidth: 640), + child: PostItem(data: _posts[idx]), + ).center(), onTap: () { GoRouter.of(context).pushNamed( 'postDetail', diff --git a/lib/screens/post/post_detail.dart b/lib/screens/post/post_detail.dart index e3b3688..7a7f7c2 100644 --- a/lib/screens/post/post_detail.dart +++ b/lib/screens/post/post_detail.dart @@ -9,6 +9,7 @@ import 'package:provider/provider.dart'; import 'package:styled_widget/styled_widget.dart'; import 'package:surface/providers/sn_attachment.dart'; import 'package:surface/providers/sn_network.dart'; +import 'package:surface/providers/userinfo.dart'; import 'package:surface/types/post.dart'; import 'package:surface/widgets/dialog.dart'; import 'package:surface/widgets/loading_indicator.dart'; @@ -71,6 +72,7 @@ class _PostDetailScreenState extends State { @override Widget build(BuildContext context) { + final ua = context.watch(); final devicePixelRatio = MediaQuery.of(context).devicePixelRatio; return Scaffold( @@ -107,10 +109,13 @@ class _PostDetailScreenState extends State { ), if (_data != null) SliverToBoxAdapter( - child: PostItem( - data: _data!, - showComments: false, - ), + child: Container( + constraints: const BoxConstraints(maxWidth: 640), + child: PostItem( + data: _data!, + showComments: false, + ), + ).center(), ), const SliverToBoxAdapter(child: Divider(height: 1)), if (_data != null) @@ -126,7 +131,7 @@ class _PostDetailScreenState extends State { ], ).padding(horizontal: 20, vertical: 12), ), - if (_data != null) + if (_data != null && ua.isAuthorized) SliverToBoxAdapter( child: Container( height: 240, @@ -157,6 +162,7 @@ class _PostDetailScreenState extends State { PostCommentSliverList( key: _childListKey, parentPostId: _data!.id, + maxWidth: 640, ), SliverGap(math.max(MediaQuery.of(context).padding.bottom, 16)), ], diff --git a/lib/widgets/post/post_comment_list.dart b/lib/widgets/post/post_comment_list.dart index 9eff88b..46c0ff0 100644 --- a/lib/widgets/post/post_comment_list.dart +++ b/lib/widgets/post/post_comment_list.dart @@ -7,6 +7,7 @@ import 'package:provider/provider.dart'; import 'package:styled_widget/styled_widget.dart'; import 'package:surface/providers/sn_attachment.dart'; import 'package:surface/providers/sn_network.dart'; +import 'package:surface/providers/userinfo.dart'; import 'package:surface/types/post.dart'; import 'package:surface/widgets/post/post_item.dart'; import 'package:surface/widgets/post/post_mini_editor.dart'; @@ -14,7 +15,12 @@ import 'package:very_good_infinite_list/very_good_infinite_list.dart'; class PostCommentSliverList extends StatefulWidget { final int parentPostId; - const PostCommentSliverList({super.key, required this.parentPostId}); + final double? maxWidth; + const PostCommentSliverList({ + super.key, + required this.parentPostId, + this.maxWidth, + }); @override State createState() => PostCommentSliverListState(); @@ -88,7 +94,12 @@ class PostCommentSliverListState extends State { onFetchData: _fetchPosts, itemBuilder: (context, idx) { return GestureDetector( - child: PostItem(data: _posts[idx]), + child: Container( + constraints: BoxConstraints( + maxWidth: widget.maxWidth ?? double.infinity, + ), + child: PostItem(data: _posts[idx]), + ).center(), onTap: () { GoRouter.of(context).pushNamed( 'postDetail', @@ -121,6 +132,7 @@ class _PostCommentListPopupState extends State { @override Widget build(BuildContext context) { + final ua = context.watch(); final devicePixelRatio = MediaQuery.of(context).devicePixelRatio; return Column( @@ -139,25 +151,26 @@ class _PostCommentListPopupState extends State { Expanded( child: CustomScrollView( slivers: [ - SliverToBoxAdapter( - child: Container( - height: 240, - decoration: BoxDecoration( - border: Border.symmetric( - horizontal: BorderSide( - color: Theme.of(context).dividerColor, - width: 1 / devicePixelRatio, + if (ua.isAuthorized) + SliverToBoxAdapter( + child: Container( + height: 240, + decoration: BoxDecoration( + border: Border.symmetric( + horizontal: BorderSide( + color: Theme.of(context).dividerColor, + width: 1 / devicePixelRatio, + ), ), ), - ), - child: PostMiniEditor( - postReplyId: widget.postId, - onPost: () { - _childListKey.currentState!.refresh(); - }, + child: PostMiniEditor( + postReplyId: widget.postId, + onPost: () { + _childListKey.currentState!.refresh(); + }, + ), ), ), - ), PostCommentSliverList( key: _childListKey, parentPostId: widget.postId,