Open nergal79 opened 6 months ago
@2000calories Checking in again . Is this a library limitation ? Can't we use these bold/italic regEx with email, link and phone regEx ? Or somehow its getting overridden . In any case Pls share your thoughts, I'll be grateful . Thanks .
Sorry for late reply. There is a conflict if two EasyRichTextPattern target the same text. Here is a workaround. You can implement the link inside the matchBuilder. Since _ (for italic effect) is common in link, I replace it with !.
EasyRichTextPattern(
targetString: '(\!)(.*?)(\!)',
matchBuilder: (BuildContext context, RegExpMatch? match) {
var boldWebText = match?[0]?.replaceAll("\!", '');
return TextSpan(
text: boldWebText,
recognizer: TapGestureRecognizer()
..onTap = () async {
Uri url = Uri.parse(boldWebText!);
if (await canLaunchUrl(url)) {
await launchUrl(url);
}
},
style: const TextStyle(
// fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic,
decoration: TextDecoration.underline,
),
);
},
),
Hi, I also have an issue with the pattern detector and the TapGetureRecognizer not being executed. I think my problem comes from the custom pattern I added for username detection because without this block of code the other two work fine.
EasyRichTextPattern(
targetString: '@' + '[A-Za-z0-9]*',
matchBuilder: (BuildContext context, RegExpMatch? match) {
String tagUserName = match[0]!;
return TextSpan(
text: tagUserName,
style: Theme.of(context).textTheme.headline3,
recognizer: TapGestureRecognizer()
..onTap = () {
print("Tag user");
});
},
style: Theme.of(context).textTheme.headline3,
),
EasyRichTextPattern(
targetString: EasyRegexPattern.webPattern,
matchBuilder: (BuildContext context, RegExpMatch? match) {
String link = match[0]!;
return TextSpan(
text: link,
style: TextStyle(
color: Colors.green,
decoration: TextDecoration.underline,
),
recognizer: TapGestureRecognizer()
..onTap = () async {
print("Open link");
},
);
},
),
EasyRichTextPattern(
targetString: EasyRegexPattern.emailPattern,
matchBuilder: (context, match) {
String link = match![0]!;
return TextSpan(
text: link,
style: TextStyle(
color: Colors.red,
decoration: TextDecoration.underline,
),
recognizer: TapGestureRecognizer()
..onTap = () {
print("Open Email");
},
);
},
),
I tried reorganising the EasyRichTextPattern classes but it didn't help. Is there anything I can do ? Is my regex the problem ? Thanks !
Sorry for late reply. There is a conflict if two EasyRichTextPattern target the same text. Here is a workaround. You can implement the link inside the matchBuilder. Since _ (for italic effect) is common in link, I replace it with !.
EasyRichTextPattern( targetString: '(\!)(.*?)(\!)', matchBuilder: (BuildContext context, RegExpMatch? match) { var boldWebText = match?[0]?.replaceAll("\!", ''); return TextSpan( text: boldWebText, recognizer: TapGestureRecognizer() ..onTap = () async { Uri url = Uri.parse(boldWebText!); if (await canLaunchUrl(url)) { await launchUrl(url); } }, style: const TextStyle( // fontWeight: FontWeight.bold, fontStyle: FontStyle.italic, decoration: TextDecoration.underline, ), ); }, ),
Thx for reply @2000calories .. I tried your solution but unfortunately it does not work .. have u tried it with provided code above with question ?
} }`
flutter doctor
Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, 3.16.9, on Microsoft Windows [Version 10.0.22631.3296], locale en-IN) [√] Windows Version (Installed version of Windows is version 10 or higher) [!] Android toolchain - develop for Android devices (Android SDK version 34.0.0) X cmdline-tools component is missing Run
path/to/sdkmanager --install "cmdline-tools;latest"See https://developer.android.com/studio/command-line for more details. X Android license status unknown. Run
flutter doctor --android-licenses` to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/windows#android-setup for more details. [√] Chrome - develop for the web [X] Visual Studio - develop Windows apps X Visual Studio not installed; this is necessary to develop Windows apps. Download at https://visualstudio.microsoft.com/downloads/. Please install the "Desktop development with C++" workload, including all of its default components [√] Android Studio (version 2023.2) [√] IntelliJ IDEA Community Edition (version 2023.2) [√] VS Code (version 1.87.2) [√] Connected device (4 available) [√] Network resources! Doctor found issues in 2 categories. `
I m using this text widget in Chat list just like whats app .. I can see all text(email, phone, links ) underlined but nothing happens when i click them .. Weird things is when i comment out last 3 patterns some how phone number , email and link starts working. Is this a library bug ? Can u pls advise what might be wrong here .