add ability to specify onLinkTap for url attachments

This commit is contained in:
Usaim Bhayat
2022-03-10 16:24:36 -05:00
parent 8f14cfe944
commit 098a541318
2 changed files with 10 additions and 1 deletions
@@ -14,6 +14,7 @@ class UrlAttachment extends StatelessWidget {
horizontal: 16,
vertical: 8,
),
this.onLinkTap,
}) : super(key: key);
/// Attachment to be displayed
@@ -28,13 +29,20 @@ class UrlAttachment extends StatelessWidget {
/// [MessageThemeData] for showing image title
final MessageThemeData messageTheme;
/// The function called when tapping on a link
final void Function(String)? onLinkTap;
@override
Widget build(BuildContext context) {
final chatThemeData = StreamChatTheme.of(context);
return GestureDetector(
onTap: () {
final titleLink = urlAttachment.titleLink;
if (titleLink != null) launchURL(context, titleLink);
if (titleLink != null) {
onLinkTap != null
? onLinkTap!(titleLink)
: launchURL(context, titleLink);
}
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -1013,6 +1013,7 @@ class _MessageWidgetState extends State<MessageWidget>
hostDisplayName: hostDisplayName,
textPadding: widget.textPadding,
messageTheme: widget.messageTheme,
onLinkTap: widget.onLinkTap,
);
}