♻️ Apply new OpenablePostItem to almost everywhere

This commit is contained in:
LittleSheep 2025-02-08 13:58:35 +08:00
parent 74882116e3
commit 2d5b3b554e
4 changed files with 89 additions and 65 deletions

View File

@ -246,10 +246,7 @@ class _ExploreScreenState extends State<ExploreScreen> {
onFetchData: _fetchPosts, onFetchData: _fetchPosts,
itemBuilder: (context, idx) { itemBuilder: (context, idx) {
return Center( return Center(
child: OpenContainer( child: OpenablePostItem(
closedBuilder: (_, __) => Container(
constraints: const BoxConstraints(maxWidth: 640),
child: PostItem(
data: _posts[idx], data: _posts[idx],
maxWidth: 640, maxWidth: 640,
onChanged: (data) { onChanged: (data) {
@ -259,22 +256,6 @@ class _ExploreScreenState extends State<ExploreScreen> {
_refreshPosts(); _refreshPosts();
}, },
), ),
),
openBuilder: (_, close) => PostDetailScreen(
slug: _posts[idx].id.toString(),
preload: _posts[idx],
onBack: close,
),
openColor: Colors.transparent,
openElevation: 0,
transitionType: ContainerTransitionType.fade,
closedColor: Theme.of(context).colorScheme.surfaceContainerLow.withOpacity(
cfg.prefs.getBool(kAppBackgroundStoreKey) == true ? 0.75 : 1,
),
closedShape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(16)),
),
),
); );
}, },
separatorBuilder: (_, __) => const Gap(8), separatorBuilder: (_, __) => const Gap(8),

View File

@ -134,7 +134,7 @@ class _PostSearchScreenState extends State<PostSearchScreen> {
body: Stack( body: Stack(
children: [ children: [
InfiniteList( InfiniteList(
padding: const EdgeInsets.only(top: 100), padding: const EdgeInsets.only(top: 100 + 8),
itemCount: _posts.length, itemCount: _posts.length,
isLoading: _isBusy, isLoading: _isBusy,
hasReachedMax: _postCount != null && _posts.length >= _postCount!, hasReachedMax: _postCount != null && _posts.length >= _postCount!,
@ -142,8 +142,7 @@ class _PostSearchScreenState extends State<PostSearchScreen> {
_fetchPosts(); _fetchPosts();
}, },
itemBuilder: (context, idx) { itemBuilder: (context, idx) {
return GestureDetector( return OpenablePostItem(
child: PostItem(
data: _posts[idx], data: _posts[idx],
maxWidth: 640, maxWidth: 640,
onChanged: (data) { onChanged: (data) {
@ -152,17 +151,9 @@ class _PostSearchScreenState extends State<PostSearchScreen> {
onDeleted: () { onDeleted: () {
_refreshPosts(); _refreshPosts();
}, },
),
onTap: () {
GoRouter.of(context).pushNamed(
'postDetail',
pathParameters: {'slug': _posts[idx].id.toString()},
extra: _posts[idx],
); );
}, },
); separatorBuilder: (_, __) => const Gap(8),
},
separatorBuilder: (context, index) => const Divider(height: 1),
), ),
Positioned( Positioned(
top: 16, top: 16,

View File

@ -597,25 +597,16 @@ class _PublisherPostList extends StatelessWidget {
hasReachedMax: postCount != null && posts.length >= postCount!, hasReachedMax: postCount != null && posts.length >= postCount!,
onFetchData: fetchPosts, onFetchData: fetchPosts,
itemBuilder: (context, idx) { itemBuilder: (context, idx) {
return GestureDetector( return OpenablePostItem(
child: PostItem(
data: posts[idx], data: posts[idx],
maxWidth: 640, maxWidth: 640,
onChanged: (data) { onChanged: (data) {
onChanged(idx, data); onChanged(idx, data);
}, },
onDeleted: onDeleted, onDeleted: onDeleted,
),
onTap: () {
GoRouter.of(context).pushNamed(
'postDetail',
pathParameters: {'slug': posts[idx].id.toString()},
extra: posts[idx],
); );
}, },
); separatorBuilder: (_, __) => const Gap(8),
},
separatorBuilder: (context, index) => const Divider(height: 1),
); );
} }
} }

View File

@ -1,6 +1,7 @@
import 'dart:io'; import 'dart:io';
import 'dart:math' as math; import 'dart:math' as math;
import 'package:animations/animations.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:easy_localization/easy_localization.dart'; import 'package:easy_localization/easy_localization.dart';
import 'package:file_saver/file_saver.dart'; import 'package:file_saver/file_saver.dart';
@ -22,6 +23,7 @@ import 'package:styled_widget/styled_widget.dart';
import 'package:surface/providers/config.dart'; import 'package:surface/providers/config.dart';
import 'package:surface/providers/sn_network.dart'; import 'package:surface/providers/sn_network.dart';
import 'package:surface/providers/userinfo.dart'; import 'package:surface/providers/userinfo.dart';
import 'package:surface/screens/post/post_detail.dart';
import 'package:surface/types/attachment.dart'; import 'package:surface/types/attachment.dart';
import 'package:surface/types/post.dart'; import 'package:surface/types/post.dart';
import 'package:surface/types/reaction.dart'; import 'package:surface/types/reaction.dart';
@ -38,6 +40,65 @@ import 'package:surface/widgets/post/publisher_popover.dart';
import 'package:surface/widgets/universal_image.dart'; import 'package:surface/widgets/universal_image.dart';
import 'package:xml/xml.dart'; import 'package:xml/xml.dart';
class OpenablePostItem extends StatelessWidget {
final SnPost data;
final bool showReactions;
final bool showComments;
final bool showMenu;
final bool showFullPost;
final double? maxWidth;
final Function(SnPost data)? onChanged;
final Function()? onDeleted;
final Function()? onSelectAnswer;
const OpenablePostItem({
super.key,
required this.data,
this.showReactions = true,
this.showComments = true,
this.showMenu = true,
this.showFullPost = false,
this.maxWidth,
this.onChanged,
this.onDeleted,
this.onSelectAnswer,
});
@override
Widget build(BuildContext context) {
final cfg = context.read<ConfigProvider>();
return OpenContainer(
closedBuilder: (_, __) => Container(
constraints: BoxConstraints(maxWidth: maxWidth ?? double.infinity),
child: PostItem(
data: data,
maxWidth: maxWidth,
showComments: showComments,
showFullPost: showFullPost,
onChanged: onChanged,
onDeleted: onDeleted,
onSelectAnswer: onSelectAnswer,
),
),
openBuilder: (_, close) => PostDetailScreen(
slug: data.id.toString(),
preload: data,
onBack: close,
),
openColor: Colors.transparent,
openElevation: 0,
transitionType: ContainerTransitionType.fade,
closedColor: Theme.of(context).colorScheme.surfaceContainerLow.withOpacity(
cfg.prefs.getBool(kAppBackgroundStoreKey) == true ? 0.75 : 1,
),
closedShape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(16)),
),
);
}
}
class PostItem extends StatelessWidget { class PostItem extends StatelessWidget {
final SnPost data; final SnPost data;
final bool showReactions; final bool showReactions;