urlMatcher function
MatchText
urlMatcher(
{ - TextStyle? style,
- dynamic onLinkPressed(
- String url
)?,
})
Implementation
MatchText urlMatcher({
final TextStyle? style,
final Function(String url)? onLinkPressed,
}) =>
MatchText(
onTap: (urlText) async {
final protocolIdentifierRegex = RegExp(
r'^((http|ftp|https):\/\/)',
caseSensitive: false,
);
if (!urlText.startsWith(protocolIdentifierRegex)) {
urlText = 'https://$urlText';
}
if (onLinkPressed != null) {
onLinkPressed(urlText);
} else {
final url = Uri.tryParse(urlText);
if (url != null && await canLaunchUrl(url)) {
await launchUrl(
url,
mode: LaunchMode.externalApplication,
);
}
}
},
pattern: regexLink,
style: style,
);