2000calories / flutter_easy_rich_text

The EasyRichText widget provides an easy way to use RichText.
https://pub.dev/packages/easy_rich_text
MIT License
80 stars 33 forks source link

Link click does not work #58

Open ashub7 opened 7 months ago

ashub7 commented 7 months ago

First of all Thanks for such a great package.

I m using EasyRichText in Chat screen similar to Whats app . In which i need handle link, phone, email , bold, italic and strikeThrough formatting. I m using the code below ->

EasyRichText( key: Key(messageId), text, defaultStyle: style, maxLines: maxLines, overflow: maxLines == null ? TextOverflow.clip : TextOverflow.ellipsis, patternList: [ EasyRichTextPattern( targetString: EasyRegexPattern.emailPattern, urlType: 'email', style: linkStyle, ), EasyRichTextPattern( targetString: EasyRegexPattern.telPattern, urlType: 'tel', style: linkStyle, ), EasyRichTextPattern( targetString: '(\)(.?)(\)', matchBuilder: (BuildContext context, RegExpMatch? match) { // print(match[0]); return TextSpan( text: match?[0]?.replaceAll('', ''), style: style.copyWith(fontWeight: FontWeight.bold), ); }, ), EasyRichTextPattern( targetString: '(_)(.?)(_)', matchBuilder: (BuildContext context, RegExpMatch? match) { // print(match[0]); return TextSpan( text: match?[0]?.replaceAll('_', ''), style: style.copyWith(fontStyle: FontStyle.italic), ); }, ), EasyRichTextPattern( targetString: '(\~)(.?)(\~)', matchBuilder: (BuildContext context, RegExpMatch? match) { return TextSpan( text: match?[0]?.replaceAll('~', ''), style: style.copyWith( decoration: TextDecoration.lineThrough, decorationColor: style.color), ); }, ), EasyRichTextPattern( targetString: EasyRegexPattern.webPattern, urlType: 'web', style: linkStyle, ), ], );

With this code the links are properly formatted with color and underlined .. But they r not clickable i.e the url does not open the browser. Also sometimes Email click also does not work .. its does work some time .. Is this a bug, limitation or something wrong with my implementation .

Also there maybe some issue with email and web regex .. it opens browser for andew.the@gmail.com and mail client for oracle@gmail.com .

2000calories commented 7 months ago

There is a conflict if two EasyRichTextPattern target the same text. You can check the workaround here. https://github.com/2000calories/flutter_easy_rich_text/issues/55#issuecomment-2038761247