Closed SNNafi closed 3 years ago
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,
),
),
],
),
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 ?
How you colored these words?
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)),
),
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),
);
},
),
],
),
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 .
Suppose I colored some text using regex. Example:
Here I have colored arabic text. When I tap on these arabic text, it gives me a message by
BUT, is there any way to get the tapped arabic text? Like when tapped on
يَنْصُرُ
it printsيَنْصُرُ
. Whenوَاحِدٌ مُذَكَّرٌ غَائِبٌ
, printsوَاحِدٌ مُذَكَّرٌ غَائِبٌ