feat: add possiblity to open a post by tapping the image

This commit is contained in:
Jacques 2025-02-19 10:20:44 +01:00
parent ddb73cf631
commit 6facc6e35c
3 changed files with 39 additions and 26 deletions

View file

@ -36,6 +36,7 @@ class TimelineOptions {
this.onTapOverview, this.onTapOverview,
this.onTapCreatePostInOverview, this.onTapCreatePostInOverview,
this.placeholderImageAssetUrl, this.placeholderImageAssetUrl,
this.tapImageToOpenPost = true,
}); });
// Builders // Builders
@ -73,6 +74,7 @@ class TimelineOptions {
final Widget? timelineScreenDrawer; final Widget? timelineScreenDrawer;
final AppBarBuilder? timelineScreenAppBarBuilder; final AppBarBuilder? timelineScreenAppBarBuilder;
final String? placeholderImageAssetUrl; final String? placeholderImageAssetUrl;
final bool tapImageToOpenPost;
} }
Widget _defaultFloatingActionButton( Widget _defaultFloatingActionButton(

View file

@ -10,6 +10,7 @@ class TappableImage extends StatefulWidget {
required this.onLike, required this.onLike,
required this.userId, required this.userId,
required this.likeAndDislikeIcon, required this.likeAndDislikeIcon,
this.onTap,
super.key, super.key,
}); });
@ -17,6 +18,7 @@ class TappableImage extends StatefulWidget {
final String userId; final String userId;
final Future<bool> Function() onLike; final Future<bool> Function() onLike;
final (Icon?, Icon?) likeAndDislikeIcon; final (Icon?, Icon?) likeAndDislikeIcon;
final VoidCallback? onTap;
@override @override
State<TappableImage> createState() => _TappableImageState(); State<TappableImage> createState() => _TappableImageState();
@ -66,6 +68,7 @@ class _TappableImageState extends State<TappableImage>
@override @override
Widget build(BuildContext context) => InkWell( Widget build(BuildContext context) => InkWell(
onTap: widget.onTap != null ? () => widget.onTap!() : null,
onDoubleTap: () async { onDoubleTap: () async {
if (loading) { if (loading) {
return; return;

View file

@ -81,6 +81,9 @@ class _TimelinePostWidgetState extends State<TimelinePostWidget> {
if (options.doubleTapToLike) ...[ if (options.doubleTapToLike) ...[
TappableImage( TappableImage(
post: post, post: post,
onTap: widget.options.tapImageToOpenPost
? () => widget.onTapPost(widget.post)
: null,
onLike: () async { onLike: () async {
if (isLikedByCurrentUser) { if (isLikedByCurrentUser) {
widget.options.onTapUnlike ?? widget.options.onTapUnlike ??
@ -108,7 +111,11 @@ class _TimelinePostWidgetState extends State<TimelinePostWidget> {
), ),
] else ...[ ] else ...[
if (post.imageUrl != null) if (post.imageUrl != null)
Container( GestureDetector(
onTap: widget.options.tapImageToOpenPost
? () => widget.onTapPost(widget.post)
: null,
child: Container(
height: 250, height: 250,
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8), borderRadius: BorderRadius.circular(8),
@ -137,6 +144,7 @@ class _TimelinePostWidgetState extends State<TimelinePostWidget> {
), ),
), ),
), ),
),
if (post.image != null) if (post.image != null)
Container( Container(
height: 250, height: 250,