Flutter - 控件之 Text
效果预览
Text
Text
显示一个样式单一的文本字符串,可以显示单行也可以显示多行。
1、Text
参数解析:
Text(
this.data, {
Key key,
this.style, //文本样式,默认DefaultTextStyle
this.strutStyle, //支柱样式
this.textAlign, //水平对齐样式,TextAlign.center居中,left,right, justify两端对齐
this.textDirection, //文本方向,TextDirection.ltr
this.locale, //通常不需要设置,根据地区显示相应的字体
this.softWrap, //文本换行处是否断行,默认true
this.overflow, //文本溢出处理,TextOverflow.ellipsis省略号
this.textScaleFactor, //文本缩放系数,默认1.0,如设置为2,则,文本大小是指定fontSize的2倍。
this.maxLines, //最大行数
this.semanticsLabel,
})
2、代码示例:
Container(
height: 100,
color: Colors.red,
child: Text(
"Performing hot reload,Syncing files to device iPhone 11 Pro Max,Reloaded 3 of 543 libraries in 203ms."
"Performing hot reload,Syncing files to device iPhone 11 Pro Max,Reloaded 3 of 543 libraries in 203ms.",
strutStyle: StrutStyle(
leading: 1, //space均匀分布在单行文本上下
),
textAlign: TextAlign.left,
textDirection: TextDirection.ltr,
softWrap: true,
overflow: TextOverflow.ellipsis,
textScaleFactor: 1,
maxLines: 3,
),
),
3、效果图:
TextStyle
TextStyle
作为Text
参数是可选的,默认使用DefaultTextStyle
,如果给定style
且TextStyle.inherit
为true
(默认),则给定样式与DefaultTextStyle
样式合并。
1、TextStyle
参数解析:
TextStyle({
this.inherit = true,
this.color, //文本字体颜色,若设置了foreground则,这个属性需要为null
this.backgroundColor, //文本背景色
this.fontSize, //字号,单位px, 默认14px
this.fontWeight, //字重,如粗体Bold .w700
this.fontStyle, //可设置斜体,FontStyle.italic斜体, FontStyle.normal
this.letterSpacing, //字符间隔,单位px, 可为负值
this.wordSpacing, //单词(空白序列)间隔, 单位px, 可为负值
this.textBaseline, //基线
this.height, //文本高度,数值为字体大小的倍数
this.locale, //不常用,用于选择特定区域符号的区域设置
this.foreground, //前景色,字体颜色,与color冲突
this.background, //背景, 与backgroundColor冲突
this.shadows, //字体阴影, 可以设置多个光源
this.decoration, //文本装饰,如下划线TextDecoration.underline,
this.decorationColor, //文本装饰颜色
this.decorationStyle, //文本装饰样式,如TextDecorationStyle.solid一条实线,.double两条实线,.dotted点线,.dashed虚线,.wavy波浪线
this