Closed tasselx closed 4 years ago
Sure. I am working on it. The reason is that the word boundary between Chinese characters is not a space. I need to find a way to make it friendly for both English and Chinese.
Please try the develop branch first. I will publish a new version later. config in pubspec.yaml
easy_rich_text:
git:
url: https://github.com/2000calories/flutter_easy_rich_text.git
ref: develop
If you have content mixed with Chinese and English like the example you show above, you need to add a space to stringBeforeTarget
EasyRichText(
"I want 世界你好 here. I want not 世界你好 font here.",
patternList: [
EasyRichTextPattern(
targetString: '世界',
stringBeforeTarget: 'want ',
style: TextStyle(color: Colors.blue),
),
],
),
Thank you for your quick response, it seems to solve some problems of Chinese characters, but I found some other problems, can't do some styles on the characters, paste some of my code
"left is right 《世界你好》thi",
defaultStyle: TextStyle(
color: Colors.red
),
patternList: [
EasyRichTextPattern(
targetString: 'ht',
style: TextStyle(color: Colors.orange)
),
EasyRichTextPattern(
targetString: '你好',
style: TextStyle(fontWeight: FontWeight.bold,color: Colors.blue),
),
EasyRichTextPattern(
targetString: '《',
style: TextStyle(fontWeight: FontWeight.bold,color: Colors.lightBlue),
),
EasyRichTextPattern(
targetString: '》',
style: TextStyle(fontWeight: FontWeight.bold,color: Colors.lightGreenAccent),
)
],
),```
Try the updated develop branch and set matchWordBoundaries: false. See the comments in the following code for explanation.
EasyRichText(
"left is right 《世界你好》thi",
defaultStyle: TextStyle(color: Colors.red),
patternList: [
EasyRichTextPattern(
// by default a complete word matches the targetString will be styled
// to match the targetString as a part of a word, set matchWordBoundaries: false
targetString: 'ht',
matchWordBoundaries: false,
style: TextStyle(color: Colors.orange)),
EasyRichTextPattern(
targetString: '你好',
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.blue),
),
EasyRichTextPattern(
//《 is not recognized as Chinese, but it works by setting matchWordBoundaries: false
targetString: '《',
matchWordBoundaries: false,
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.lightBlue),
),
EasyRichTextPattern(
targetString: '》',
matchWordBoundaries: false,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.lightGreenAccent),
)
],
),
I tested the code and it works. If I have some text with the same content and I only match the first one, or one of them, or all of them, how do I do it? , but this is not a bug, maybe a requirement . In addition to these authors, is there any plan to support gesture response and some regular matches such as url, phone number, email, etc.
--If I have some text with the same content and I only match the first one, or one of them, or all of them, how do I do it? Please open another issue to request this function and I will follow you up once it is ready.
--In addition to these authors, is there any plan to support gesture response and some regular matches such as url, phone number, email, etc. Integration with url_launcher is in my plan. Gesture response may be too much for this widget.
Just a reminder, please switch to the lastest version instead of the develop branch.
dependencies:
easy_rich_text: '^0.3.2'
I'm glad to see the library you published on pub dev, but it is a bit imperfect because it cannot support Chinese characters. Would you fix this bug?