如何在Text小部件内加下划线?

我似乎在TextStylefontStyle属性中找不到下划线

推荐答案

在给所有内容加下划线时,您可以在文本小部件上设置TextStyle.

enter image description here

Text(
  'Hello world',
  style: TextStyle(
    decoration: TextDecoration.underline,
  ),
)

如果您只想给文本的一部分加下划线,那么您需要使用Text.rich()(或RichText小部件)并将字符串拆分成可以添加样式的TextSpans.

enter image description here

Text.rich(
  TextSpan(
    text: 'Hello ',
    style: TextStyle(fontSize: 50),
    children: <TextSpan>[
      TextSpan(
          text: 'world',
          style: TextStyle(
            decoration: TextDecoration.underline,
          )),
      // can add more TextSpans here...
    ],
  ),
)

TextSpan有点奇怪.text参数是默认样式,但children列表包含紧随其后的已设置样式(也可能未设置样式)的文本.如果要从带样式的文本开始,可以使用空字符串表示text.

您还可以添加TextDecorationStyle以更改装饰的外观.下面是虚线:

enter image description here

Text(
  'Hello world',
  style: TextStyle(
    decoration: TextDecoration.underline,
    decorationStyle: TextDecorationStyle.dashed,
  ),
)

TextDecorationStyle.dotted:

enter image description here

TextDecorationStyle.double:

enter image description here

TextDecorationStyle.wavy:

enter image description here

Flutter相关问答推荐

Flutter -带有TextAlign.right的文本字段不显示空白

当未聚焦且非空时,在flutter中更改文本字段的标签 colored颜色

为什么我不能看到类音频源在flutter?'

如何在Firebase项目中更改包名称和包ID

从超级应用程序启动时,Flutter 小应用程序中未加载资源

Flutter OpenID Connect无效参数:redirect_uri using Keycloak

将列表<;Events>;从Flutter 应用程序中的函数传回EventLoader属性时出错

Flutter :URI的目标不存在

在Flutter 小部件测试中找不到框中的AssetImage装饰

Flutter Android Google Sign-in error:ApiException:10在确认软件包名称、SHA-1 fingerprint 和设置同意页面后出现异常

Flutter卡内容未在水平列表视图中居中

如何在 Flutter 中设计像 zomato 应用程序一样的搜索字段?

Flutter 中的 Provider 不会在第一次构建 App 时返回

Flutter url_launcher 插件抛出java.lang.IllegalArgumentException:接收器未注册:io.flutter.plugins.urllauncher.WebViewActivity

在提供程序包更改通知程序中构建倒计时时钟

如何在 flutter 中过滤 DateTime(intl)?

将一个 Flutter 应用程序集成到另一个 Flutter 应用程序中

如何在flutter中共享容器和gridview之间的滚动条?

Flutter Firebase:如何判断返回值是否是特定对象

未处理的异常:FileSystemException:无法打开文件,路径 = 'assets/res.zip'(操作系统错误:没有这样的文件或目录,errno = 2)