0

我想给我的文本一个边框或背景。只是一个简单的红色文本,周围有黑色边框。

请参阅下图作为灵感:

在此处输入图像描述

4

3 回答 3

2

只需在颤振文档中查找 TextStyle 类。我相信在 Borders an Stroke 上,您会找到答案。

颤振文档

于 2021-12-13T12:27:10.827 回答
0

请参阅此处outlined_text的包装

你也可以试试这个https://pub.dev/packages/bordered_text

于 2021-12-13T12:00:18.303 回答
0

我在Flutter 文档中找到了答案

没有边框属性,但是您可以使用两个重叠的文本来完成这项工作。这是代码

Stack(
  children: <Widget>[
    // Stroked text as border.
    Text(
      'WHO',
      style: TextStyle(
        fontSize: 40,
        foreground: Paint()
          ..style = PaintingStyle.stroke
          ..strokeWidth = 6
          ..color = Colors.grey,
      ),
    ),
    // Solid text as fill.
    Text(
      'WHO',
      style: TextStyle(
        fontSize: 40,
        color: Colors.red,
      ),
    ),
  ],
)
于 2021-12-13T14:00:36.443 回答