如何在颤振文本小部件内下划线文本?
我似乎无法在TextStyle的fontStyle属性内找到下划线
如何在颤振文本小部件内下划线文本?
我似乎无法在TextStyle的fontStyle属性内找到下划线
当前回答
或者,为了防止复杂性,您也可以使用Flutter Markdown https://pub.dev/packages/flutter_markdown
其他回答
你可以在样式中使用TextDecoration来强调给定的文本。
例如
Text(
"Your text here",
style: TextStyle(
decoration: TextDecoration.underline),
)
)
另一个例子
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,
)
),
]
),
),
输出:
例如
Text(
"Terms and Condition",
style: TextStyle(
decoration:
TextDecoration.underline,
height: 1.5,
fontSize: 15,
fontWeight: FontWeight.bold,
fontFamily: 'Roboto-Regular',
),
),
你可以通过应用decoration: TextDecoration来实现。下划线到文本的TextStyle。
主题示例:
Text(
"text",
style: Theme
.of(context)
.accentTextTheme
.subhead
.copyWith(decoration: TextDecoration.underline),
)
基本的例子:
Text(
"text",
style: TextStyle(decoration: TextDecoration.underline),
)
最自定义的方法是将文本包装在容器中,并给出底部边框。你也可以根据你的设计给文本和下划线之间的空格。请参考乔·穆勒,最后一个选择。
Container(
padding: const EdgeInsets.only(
bottom: 5, // Space between underline and text
),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(
color: Colors.amber,
width: 2.0, // Underline thickness
))
),
child: Text(
"Forgot Password?",
style: TextStyle(
color: Colors.black,
),
),
)