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

View file

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

View file

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