本文主要介绍Flutter中非常常见的Text,列举了一些实际例子介绍如何使用。
1.0 组成
Text的组成如下:
- '' ": 文本输入信息。
- textDirection:文本方向(ltr 从左至右,rtl 从右至 左)
- textAlign:文本对齐方式,center 居中,left 左对齐,right右对齐,justfy两端对齐
- overflow:文字超出屏幕之后的处理方式(clip 裁剪,fade 渐隐,ellipsis 省略号)
- textScaleFactor:字体显示倍率
- maxLines:文字显示最大行
- style:字体的样式设置
TextStyle 的参数 :
- decoration:文字装饰线(none 没有线,lineThrough 删 除线,overline 上划线,underline 下划线)
- decorationColor:文字装饰线颜色
- decorationStyle:文字装饰线风格([dashed,dotted]虚线, double 两根线,solid 一根实线,wavy 波浪 线)
- wordSpacing:单词间隙(如果是负值,会让单词变得更紧凑)
- letterSpacing:字母间隙(如果是负值,会让字母变得更紧 凑
- fontStyle:文字样式(italic 斜体,normal 正常体)
- fontSize:文字大小
- color:文字颜色
- fontWeight:字体粗细(bold 粗体,normal 正常体)
2.0 使用
Container参数的使用如下:
Text(
'Holle Word',
textAlign:TextAlign.center,
overflow:TextOverflow.fade ,
maxLines: 2,
textScaleFactor: 2,
style: TextStyle(
fontSize:16.0,
color: Colors.yellow,
fontWeight: FontWeight.w800,
fontStyle: FontStyle.italic,
decoration: TextDecoration.lineThrough,
decorationColor:Colors.white,
decorationStyle: TextDecorationStyle.dashed,
letterSpacing: 5.0
),
)