flutter_chat_ui
flutter_chat_ui copied to clipboard
Add an onLinkClicked feature
Add an onLinkClicked feature
Is your feature request related to a problem?
A clear and concise description of what the problem is or why we should process it. Whenever any link is clicked in the messages being sent, I would like to display them in app instead of redirecting to external browser. I think it will be useful for clicktracking as well
What solution would you suggest?
A clear and concise description of what you want to happen. How would it solve the problem of yours?
Is there any additional solution to that?
A clear and concise description of any alternative solutions or features you've considered. Could not find any
Extras
Screenshots or videos 📸 If applicable, add screenshots or videos to help explain your feature.
Code snippets 📝 If applicable, add code samples to help explain your feature.
// Your snippet here...
Related issues/PRs
Let us know if this is related to any issue/pull request.
Hi there, Have you find a way to intercept the link before it gets opened in the device browser? I gotta open it in-app... I have it to work if the message (bubble) is tapped but not if it's the link being hit directly... Any luck?
Found a way... In your Chat() where you have the
messages: _messages,
onAttachmentPressed: _handleAttachmentPressed,
onMessageTap: _handleMessageTap,
onPreviewDataFetched: _handlePreviewDataFetched,
onSendPressed: _handleSendPressed,
I have added:
usePreviewData: false, //(not sure it's required)
textMessageOptions: const TextMessageOptions(isTextSelectable: false),
Then it's _handleMessageTap working for me
if (message is types.TextMessage) {
var link = '';
final tempLink = message.previewData?.link;
if (tempLink != null) {
link = tempLink;
} else {
RegExp exp = RegExp(r'(?:(?:https?|ftp):\/\/)?[\w/\-?=%.]+\.[\w/\-?=%.]+');
Iterable<RegExpMatch> matches = exp.allMatches(message.text);
if (matches.isNotEmpty) {
link = message.text.substring(matches.first.start, matches.first.end);
}
}
debugPrint('link in message: ${link != '' ? link : 'NO LINK FOUND'}');
Navigator.of(context).pushNamed(WebViewScreen.routeName);
}else ...