Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

want to use recoginizer with captured string #11

Closed
ogata-k opened this issue Dec 22, 2020 · 8 comments
Closed

want to use recoginizer with captured string #11

ogata-k opened this issue Dec 22, 2020 · 8 comments

Comments

@ogata-k
Copy link

ogata-k commented Dec 22, 2020

i want to use recoginizer with captured string.

now:
EasyRichTextPattern( recognizer: TapGestureRecognizer() ..onTap = (){ ... } );

change to:
EasyRichTextPattern( recognizer: (String captured) => TapGestureRecognizer() ..onTap = (){ ... } );

can do it ?

@2000calories
Copy link
Owner

What do you mean "captured string"?

@ogata-k
Copy link
Author

ogata-k commented Dec 23, 2020

url, email, tel number and so on

@2000calories
Copy link
Owner

the captured string is not the targetString?

@ogata-k
Copy link
Author

ogata-k commented Dec 23, 2020

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.

@2000calories
Copy link
Owner

Sorry for the late response. Basically the str variable is the targerString. If not, the recognizer will not be triggered.

@ogata-k
Copy link
Author

ogata-k commented Jan 16, 2021

Then, if urlType is url, 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.

@2000calories
Copy link
Owner

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),
    ),
  ],
),

@ogata-k
Copy link
Author

ogata-k commented Jan 16, 2021

Is it same the way when use regex?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants