如何在颤振文本小部件内下划线文本?

我似乎无法在TextStyle的fontStyle属性内找到下划线


当前回答

你可以在样式中使用TextDecoration来强调给定的文本。

例如

Text(
    "Your text here",
    style: TextStyle(
        decoration: TextDecoration.underline),
    )
)

其他回答

或者,为了防止复杂性,您也可以使用Flutter Markdown https://pub.dev/packages/flutter_markdown

下面是一个简单的代码

Text(
  'Welcome to Flutter',
  style: TextStyle(decoration:TextDecoration.underline,),
),

您可以使用decorationStyle来定制它

Text(
  'Welcome to Flutter',
  style: TextStyle(
  fontSize: 24,
  decoration: TextDecoration.underline,
  decorationStyle: TextDecorationStyle.double,
  ),
),

以下是其他TextDecorationStyle值:

TextDecorationStyle.dashed TextDecorationStyle.dotted TextDecorationStyle.double TextDecorationStyle.wavy

例如

Text(
  "Terms and Condition",
  style: TextStyle(
    decoration:
        TextDecoration.underline,
    height: 1.5,
    fontSize: 15,
    fontWeight: FontWeight.bold,
    fontFamily: 'Roboto-Regular',
  ),
),

另一个例子

child: Text.rich(
  TextSpan(
    text: 'By using our mobile app, you agree to our ',
    children: [
      TextSpan(
        text: 'Term of Use',
        style: TextStyle(
          decoration: TextDecoration.underline,
        )
      ),
      TextSpan(text: ' and '),
      TextSpan(
        text: 'Privacy Policy',
        style: TextStyle(
          decoration: TextDecoration.underline,
        )
      ),
    ]
  ),
),

输出:

风格:TextStyle ( 装饰:TextDecoration.underline, ),