删除TextSpan后面的透明孔



我正在尝试为文本添加背景色,因为我不想使用容器,但不知从哪里来了一个透明的洞。我该如何解决?

我的代码是

RichText(
text: TextSpan(text: 'TEST: ', children: [
TextSpan(
text: 'HELLO',
style: TextStyle(
background: Paint()
..color = Colors.red
..strokeWidth = 10
..style = PaintingStyle.stroke,
fontWeight: FontWeight.bold),
)
]),
)

它是一个颜色为绿色的容器的子对象。

我得到的输出如在文本后面的这个图像中";你好;。

如何使红色不透明?

使用PaintingStyle.fill而不是笔划或增加笔划宽度,直到孔消失

RichText(
text: TextSpan(text: 'TEST: ', children: [
TextSpan(
text: 'HELLO',
style: TextStyle(
background: Paint()
..color = Colors.red
..strokeWidth = 10
..style = PaintingStyle.fill,
fontWeight: FontWeight.bold),
)
]),
),

您可以删除strokeWidth并用PaintingStyle.fill替换绘画风格。

RichText(text: TextSpan(text: 'TEST: ', 
children: [
TextSpan(
text: 'HELLO',
style: TextStyle(
background: Paint()
..color = Colors.red
..style = PaintingStyle.fill,
fontWeight: FontWeight.bold),
)
]),
),

最新更新