mirror of
https://github.com/Iconica-Development/flutter_timeline.git
synced 2025-05-19 10:33:44 +02:00
feat: add possiblity to open a post by tapping the image
This commit is contained in:
parent
ddb73cf631
commit
6facc6e35c
3 changed files with 39 additions and 26 deletions
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue