Closed ogata-k closed 3 years ago
What do you mean "captured string"?
url, email, tel number and so on
the captured string is not the targetString?
No. "captured string" is the str variable in this default url-luncher function in flutter_easy_rich_text library.
TapGestureRecognizer tapGestureRecognizerForUrls(String str, String urlType) {
TapGestureRecognizer tapGestureRecognizer;
switch (urlType) {
case 'web':
if (str.substring(0, 4) != "http") {
str = "https://$str";
}
tapGestureRecognizer = TapGestureRecognizer()
..onTap = () {
_launchURL(str);
};
break;
case 'email':
tapGestureRecognizer = TapGestureRecognizer()
..onTap = () {
_launchURL("mailto:$str");
};
break;
case 'tel':
tapGestureRecognizer = TapGestureRecognizer()
..onTap = () {
_launchURL("tel:$str");
};
break;
default:
}
return tapGestureRecognizer;
}
if targetString is regex pattern's string, then captured string by the regex.
Sorry for the late response. Basically the str
variable is the targerString. If not, the recognizer will not be triggered.
Then, if urlType
isurl
, can I use a self-defined function of type Future <void> Function (String)
?
I want to use targetString as arg of the self-defined function.
If you do not want the default url behaviour then do not use the urlType
option, do what you want in the recognizer.
printTargetString(targetString) {
print(targetString);
}
var targetString = "https://pub.dev/packages/easy_rich_text";
EasyRichText(
"Here is a website https://pub.dev/packages/easy_rich_text. Here is a email address test@example.com. Here is a telephone number +852 12345678.",
patternList: [
EasyRichTextPattern(
targetString: targetString,
// urlType: 'web',if you do not want the default behaviour then do not use this option, do what you want in the recognizer.
style: TextStyle(
decoration: TextDecoration.underline,
),
recognizer: TapGestureRecognizer()
..onTap = () => printTargetString(targetString),
),
],
),
Is it same the way when use regex?
i want to use recoginizer with captured string.
now:
EasyRichTextPattern( recognizer: TapGestureRecognizer() ..onTap = (){ ... } );
change to:
EasyRichTextPattern( recognizer: (String captured) => TapGestureRecognizer() ..onTap = (){ ... } );
can do it ?