Closed
Description
I want to add a background to text, here is my code:
RichText(
text: TextSpan(
text: "不科学1111",
style: TextStyle(
color: Colors.black,
background: new Paint()..color = Colors.pinkAccent,
),
children: [
TextSpan(
text: "不科学sdfsdfkd",
style: TextStyle(
color: Colors.lightGreenAccent,
background: new Paint()
..color = Colors.pinkAccent,
),
),
]),
),
But the Simplified Chinese words do not display:
If I set the background color with opacity, it seems well:
RichText(
text: TextSpan(
text: "不科学1111",
style: TextStyle(
color: Colors.black,
background: new Paint()..color = Colors.pinkAccent.withOpacity(0.5),
),
children: [
TextSpan(
text: "不科学sdfsdfkd",
style: TextStyle(
color: Colors.lightGreenAccent,
background: new Paint()
..color = Colors.pinkAccent,
),
),
]),
)
But it still doesn't meet my expectation:
I have added app locales supports like this:
supportedLocales: [
const Locale('zh', 'CH'),
const Locale('en', 'US'),
],
Still doesn't work.
Activity
zoechi commentedon Nov 14, 2018
Please add the output of
flutter doctor -v
.yumi0629 commentedon Nov 14, 2018
jason-simmons commentedon Nov 14, 2018
I can reproduce this on a Nexus 5X. It happens with both GL and software rendering back ends.
The glyphs render as expected if I remove the
drawRect
call that draws the background inParagraph::PaintBackground
. But the CJK glyphs disappear if the background rectangle is drawn before the text blob is drawn.Interestingly, this bug seems to be sensitive to text size and placement of the text blobs within a line. On the Nexus 5X, if I set the parent TextStyle's fontSize to 80.0, then all the glyphs will render on top of the background as expected.
I suspect this is happening somewhere within Skia.
GaryQian commentedon Nov 15, 2018
Could be related to #24234?
[-]Simplified Chinese letters with background do not display properly in RichText.[/-][+]Simplified Chinese characters with background do not display properly in RichText.[/+]yumi0629 commentedon Nov 15, 2018
Thanks a lot. It is true that using multiple language styles will cause this problem. But I can't understand why when I set the background color with opacity, the characters will be seen?
ozexpert commentedon Dec 22, 2018
Is there any workaround for this? this blocking my app to be released. This is not just an issue with Chinese, it's also a problem with any unicode characters (in my case, it's Korean).
GaryQian commentedon Dec 22, 2018
When the span is broken into multiple runs (due to language/font differences), we iterate through each run and paint in the order of:
I suspect that the background for the chinese is painting, then we paint the text, however, when painting the 1111, the background is painting again, covering the chinese.
I will experiment with the painting order, and see if I can figure out what is happening.
22 remaining items