如何在 Flutter 中为文本添加边框/背景?

问题描述 投票:0回答:3

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

请参阅以下图片作为灵感:

flutter text border flutter-text
3个回答
3
投票

只需在 flutter 文档中查找 TextStyle 类即可。我相信在《边界与中风》中你会找到答案。

Flutter 文档


2
投票

我在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,
      ),
    ),
  ],
)

1
投票

请参阅

outlined_text
配套这里

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

© www.soinside.com 2019 - 2024. All rights reserved.