Skip to content

Commit

Permalink
feat: make link opening on title/image tap optional
Browse files Browse the repository at this point in the history
  • Loading branch information
felixgabler committed Feb 6, 2022
1 parent 530d112 commit f20b2c9
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/src/widgets/link_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class LinkPreview extends StatefulWidget {
this.metadataTitleStyle,
this.onLinkPressed,
required this.onPreviewDataFetched,
this.openOnPreviewImageClick = false,
this.openOnPreviewTitleClick = false,
this.padding,
required this.previewData,
required this.text,
Expand Down Expand Up @@ -72,6 +74,12 @@ class LinkPreview extends StatefulWidget {
/// preview data again.
final void Function(PreviewData) onPreviewDataFetched;

/// Open the link when the link preview image is clicked. Defaults to false.
final bool openOnPreviewImageClick;

/// Open the link when the link preview title is clicked. Defaults to false.
final bool openOnPreviewTitleClick;

/// Padding around initial text widget
final EdgeInsets? padding;

Expand Down Expand Up @@ -205,7 +213,8 @@ class _LinkPreviewState extends State<LinkPreview>
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
GestureDetector(
onTap: () => _onOpen(data.link!),
onTap:
widget.openOnPreviewTitleClick ? () => _onOpen(data.link!) : null,
child: Container(
padding: EdgeInsets.only(
bottom: _padding.bottom,
Expand Down Expand Up @@ -296,7 +305,7 @@ class _LinkPreviewState extends State<LinkPreview>

Widget _imageWidget(String imageUrl, String linkUrl, double width) {
return GestureDetector(
onTap: () => _onOpen(linkUrl),
onTap: widget.openOnPreviewImageClick ? () => _onOpen(linkUrl) : null,
child: Container(
constraints: BoxConstraints(
maxHeight: width,
Expand Down Expand Up @@ -341,7 +350,9 @@ class _LinkPreviewState extends State<LinkPreview>
children: <Widget>[
Expanded(
child: GestureDetector(
onTap: () => _onOpen(data.link!),
onTap: widget.openOnPreviewTitleClick
? () => _onOpen(data.link!)
: null,
child: Container(
margin: const EdgeInsets.only(right: 4),
child: Column(
Expand Down Expand Up @@ -370,7 +381,7 @@ class _LinkPreviewState extends State<LinkPreview>
Radius.circular(12),
),
child: GestureDetector(
onTap: () => _onOpen(linkUrl),
onTap: widget.openOnPreviewImageClick ? () => _onOpen(linkUrl) : null,
child: SizedBox(
height: 48,
width: 48,
Expand Down

0 comments on commit f20b2c9

Please sign in to comment.