Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/src/models/message_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class MessageOptions {
this.parsePatterns,
this.textBeforeMedia = true,
this.onTapMedia,
this.onTapLink,
this.showTime = false,
this.timeFormat,
this.messageTimeBuilder,
Expand Down Expand Up @@ -198,6 +199,10 @@ class MessageOptions {
/// Will not work with the default video player
final void Function(ChatMedia media)? onTapMedia;

/// Function to call when the user clicks on a link.
/// Returns false when default behavior is desired.
final bool Function(String value, String? href, String title)? onTapLink;

/// Border radius of the chat bubbles
///
/// Default to: `18.0`
Expand Down
13 changes: 9 additions & 4 deletions lib/src/widgets/message_row/default_message_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,15 @@ class DefaultMessageText extends StatelessWidget {
selectable: true,
styleSheet: messageOptions.markdownStyleSheet,
onTapLink: (String value, String? href, String title) {
if (href != null) {
openLink(href);
} else {
openLink(value);
final bool Function(String value, String? href, String title)?
customOnTapLink = messageOptions.onTapLink;
if (customOnTapLink == null ||
!customOnTapLink(value, href, title)) {
if (href != null) {
openLink(href);
} else {
openLink(value);
}
}
},
)
Expand Down