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

Print onTap string #24

Closed
SNNafi opened this issue Nov 7, 2021 · 6 comments
Closed

Print onTap string #24

SNNafi opened this issue Nov 7, 2021 · 6 comments

Comments

@SNNafi
Copy link

SNNafi commented Nov 7, 2021

Suppose I colored some text using regex.
Example:

Text  يَنْصُرُ More text

Text وَاحِدٌ مُذَكَّرٌ غَائِبٌ text يَنْصُرُ text

Here I have colored arabic text. When I tap on these arabic text, it gives me a message by

recognizer: TapGestureRecognizer()
                        ..onTap = () {

                          print("Tap recognizer to print this sentence.");
    },

BUT, is there any way to get the tapped arabic text? Like when tapped on يَنْصُرُ it prints يَنْصُرُ . When وَاحِدٌ مُذَكَّرٌ غَائِبٌ , prints وَاحِدٌ مُذَكَّرٌ غَائِبٌ

@2000calories
Copy link
Owner

Is this what you want?

  var targetString1 = "tartget 1";
  var targetString2 = "tartget 2";


  EasyRichText(
    "Tap recognizer to print tartget 1.Tap recognizer to print tartget 2.",
    patternList: [
      EasyRichTextPattern(
        targetString: targetString1,
        recognizer: TapGestureRecognizer()
          ..onTap = () {
            print(targetString1);
          },
        style: TextStyle(
          decoration: TextDecoration.underline,
        ),
      ),
      EasyRichTextPattern(
        targetString: targetString2,
        recognizer: TapGestureRecognizer()
          ..onTap = () {
            print(targetString2);
          },
        style: TextStyle(
          decoration: TextDecoration.underline,
        ),
      ),
    ],
  ),

@SNNafi
Copy link
Author

SNNafi commented Nov 8, 2021

Thanks for the quick response. BUT, you have hardcoded the texts. In my case these are dynamic. So there is no way to know them before. I just to get the tapped the word when it is tapped dynamically. Is it possible ?

@2000calories
Copy link
Owner

How you colored these words?

@SNNafi
Copy link
Author

SNNafi commented Nov 8, 2021

Like this

EasyRichTextPattern(
                            targetString:
                                "[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufbc1]|[\ufbd3-\ufd3f]|[\ufd50-\ufd8f]|[\ufd92-\ufdc7]|[\ufe70-\ufefc]|[\uFDF0-\uFDFD]",
                            recognizer: TapGestureRecognizer()
                              ..onTap = () {
                                
                              },
                            style: GoogleFonts.amiri(
                                textStyle: TextStyle(
                                    color: Colors.white,
                                    fontSize: 34,
                                    fontStyle: FontStyle.normal)),
                          ),

@2000calories
Copy link
Owner

You can use matchBuilder to get every word that match the regex expression and then implement TapGestureRecognizer. However, the behaviour of Arabic words in regex is strange to me. I cannot find the word boundary for arabic character.

  EasyRichText(
    "Text وَاحِدٌ مُذَكَّرٌ غَائِبٌ text يَنْصُرُ text",
    patternList: [
      EasyRichTextPattern(
        targetString: "[\u0600-\u06ff]|[\u0750-\u077f]|[\ufb50-\ufbc1]|[\ufbd3-\ufd3f]|[\ufd50-\ufd8f]|[\ufd92-\ufdc7]|[\ufe70-\ufefc]|[\uFDF0-\uFDFD]",
        matchBuilder:
            (BuildContext context, RegExpMatch match) {
          var targetString = match[0];
          return TextSpan(
            text: targetString,
            recognizer: TapGestureRecognizer()
              ..onTap = () {
                print(targetString);
              },
            style: TextStyle(color: Colors.red),
          );
        },
      ),
    ],
  ),

@SNNafi
Copy link
Author

SNNafi commented Nov 8, 2021

Thank you. I will try. In android using \p{InArabic}+ gives you every arabic word. That was quite easy. But in dart, it is quite hard. Every pattern I have found has a different result !. And the above i.e \p{InArabic}+ doesn't work in dart .

@SNNafi SNNafi closed this as completed Nov 8, 2021
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