[英]is there any way to make Text and Underline different colors in Flutter?
First you have to use the Material
widget and within it you define a RichText
, TextSpan
and a Text
.首先,您必须使用
Material
小部件,并在其中定义RichText
、 TextSpan
和Text
。
Inside the Material
widget you need to set underline color.在
Material
小部件中,您需要设置下划线颜色。
Material(
child:RichText(),//input our need
);
You can use decorationColor: yourColor inside your Text attribute to change the underline's color.您可以在 Text 属性中使用decorationColor: yourColor 来更改下划线的颜色。 For example, if you want to underline all of your text:
例如,如果您想为所有文本加下划线:
Text("Your text",
style: TextStyle(
color: Colors.white
decoration: TextDecoration.underline,
decorationColor: Colors.yellow,
))
In case you want to underline only a part of text you have to use RichText with TextSpan.如果您只想在文本的一部分下划线,则必须将 RichText 与 TextSpan 结合使用。 For example:
例如:
RichText(
text: TextSpan(
children: [
TextSpan(
text: "NOT UNDERLINED TEXT",
style: TextStyle(
color: Colors.white)
),
TextSpan(
text: "UNDERLINED TEXT",
style: TextStyle(
color: Colors.white
decoration: TextDecoration.underline,
decorationThickness: 2,
decorationStyle: TextDecorationStyle.wavy))
],
style: TextStyle(color: Colors.yellow)
))
You can achieve this behaviour with a RichText .您可以使用RichText实现此行为。
RichText(
text: TextSpan(
text: 'You should only use this app when it is safe and legal to do so. ',
style: TextStyle(color: Colors.white),
children: [
TextSpan(
text: 'Please read our ',
style: TextStyle(
color: Colors.white,
),
children: [
TextSpan(
text: 'Privacy Policy',
style: TextStyle(
decoration: TextDecoration.underline,
decorationColor: Colors.yellow,
fontWeight: FontWeight.bold,
color: Colors.white,
),
)
],
),
],
),
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.