findLinkText method
Implementation
EySpecialText? findLinkText(
String? data, String? textStack, int? index, TextStyle? textStyle, SpecialTextGestureTapCallback? tapCallback) {
String sub = '';
String startFlag = '';
if (textStack?.endsWith("http://") ?? false) {
startFlag = 'http://';
sub = data?.substring(index ?? 0 - (startFlag.length - 1)) ?? '';
} else if (textStack?.endsWith("https://") ?? false) {
startFlag = 'https://';
sub = data?.substring(index ?? 0 - (startFlag.length - 1)) ?? '';
}
if (sub.isEmptyString) {
return null;
}
var regular = r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+";
var regex = RegExp(regular, caseSensitive: false);
if (!regex.hasMatch(sub)) {
return null;
}
var firstMatch = regex.firstMatch(sub);
var text = firstMatch?.group(0);
var linkTextStyle = textStyle?.copyWith(color: linkFontColor ?? Colors.blue, fontSize: linkFontSize ?? 16.0);
var specialText = LinkText(
targetText: text, textStyle: linkTextStyle, tapCallback: tapCallback, start: index, extrasMap: extrasMap);
specialText.setStartFlag(startFlag);
specialText.setTextType(SpecialTextType.link);
specialText.setOffset(0);
return specialText;
}