作者:_忘却的思念_ | 来源:互联网 | 2022-12-05 19:38
如何在Flutter中装饰文字笔划?这就像-webkit-text-stroke-CSS
1> PieterAelse..:
我也在寻找这个,但是找不到它.但我确实在TextStyle中找到了使用4个阴影的解决方法:
Text("Border test",
style: TextStyle(
inherit: true,
fontSize: 48.0,
color: Colors.pink,
shadows: [
Shadow( // bottomLeft
offset: Offset(-1.5, -1.5),
color: Colors.white
),
Shadow( // bottomRight
offset: Offset(1.5, -1.5),
color: Colors.white
),
Shadow( // topRight
offset: Offset(1.5, 1.5),
color: Colors.white
),
Shadow( // topLeft
offset: Offset(-1.5, 1.5),
color: Colors.white
),
]
),
);
我还在GitHub上打开了一个问题:https://github.com/flutter/flutter/issues/24108
2> Gary Qian..:
由于在TextStyle中添加了前景色,因此无需任何变通方法即可进行中风。TextStyle文档中添加了填充边框文本下方的笔触的显式示例:https : //master-api.flutter.dev/flutter/painting/TextStyle-class.html#painting.TextStyle.6
此示例在此处转载:
Stack(
children: [
// Stroked text as border.
Text(
'Greetings, planet!',
style: TextStyle(
fontSize: 40,
foreground: Paint()
..style = PaintingStyle.stroke
..strokeWidth = 6
..color = Colors.blue[700],
),
),
// Solid text as fill.
Text(
'Greetings, planet!',
style: TextStyle(
fontSize: 40,
color: Colors.grey[300],
),
),
],
)
可以通过删除堆栈并仅使用第一个笔触文本小部件来单独进行笔划。笔划/填充顺序也可以通过交换第一个和第二个“文本”小部件来调整。