¿Cómo subrayar el texto en Flutter dentro del Textwidget?
Parece que no puedo encontrar el subrayado dentro de la fontStylepropiedad deTextStyle
Al subrayar todo, puede establecer un TextStyle en el widget de texto.
Text(
'Hello world',
style: TextStyle(
decoration: TextDecoration.underline,
),
)
Si solo desea subrayar parte del texto, entonces debe usar Text.rich()(o un widget RichText) y dividir la cadena en TextSpans a los que puede agregar un estilo.
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 es un poco extraño. El textparámetro es el estilo predeterminado, pero la childrenlista contiene el texto con estilo (y posiblemente sin estilo) que lo sigue. Puede usar una cadena vacía textsi desea comenzar con texto con estilo.
También puede agregar un TextDecorationStyle para cambiar el aspecto de la decoración. Aquí está punteado:
Text(
'Hello world',
style: TextStyle(
decoration: TextDecoration.underline,
decorationStyle: TextDecorationStyle.dashed,
),
)
y TextDecorationStyle.dotted:
y TextDecorationStyle.double:
y TextDecorationStyle.wavy:
Lo haces aplicando
decoration: TextDecoration.underlineaTextStylede aText.Con ejemplo de tema:
Text( "text", style: Theme .of(context) .accentTextTheme .subhead .copyWith(decoration: TextDecoration.underline), )Ejemplo básico:
Text( "text", style: TextStyle(decoration: TextDecoration.underline), )fuente
Puede utilizar TextDecoration con estilo para subrayar un texto determinado.
Por ejemplo
Text( "Your text here", style: TextStyle( decoration: TextDecoration.underline), ) )fuente
por ejemplo
Text( "Terms and Condition", style: TextStyle( decoration: TextDecoration.underline, height: 1.5, fontSize: 15, fontWeight: FontWeight.bold, fontFamily: 'Roboto-Regular', ), ),fuente