Flutter - Text
简介
text,文本控件,用来展示文本内容
构造
const Text(this.data, {Key key,this.style,this.textAlign,this.textDirection,this.locale,this.softWrap,this.overflow,this.textScaleFactor,this.maxLines,this.semanticsLabel,}const Text.rich(this.textSpan, {Key key,this.style,this.textAlign,this.textDirection,this.locale,this.softWrap,this.overflow,this.textScaleFactor,this.maxLines,this.semanticsLabel,}
属性介绍
style
style是Text的样式集合,主要是Text本身的显示样式。
color
文字的颜色
fontSize
文字的大小
fontWeight
字重,粗体等会使用此字段
fontStyle
字体,需要斜体时会使用此字段
letterSpacing
字间距
textBaseline
对齐文本的水平线:
TextBaseline.alphabetic:文本基线是标准的字母基线
TextBaseline.ideographic:文字基线是表意字基线;如果字符本身超出了alphabetic 基线,那么ideograhpic基线位置在字符本身的底部。
height
行高
会乘以fontSize,所以不以设置过大
decoration
通常用来添加下划线、上划线和删除线
decorationColor
与decoration相关,修改划线的颜色
fontFamily
字体
textAlign
enum TextAlign {/// Align the text on the left edge of the container.left,/// Align the text on the right edge of the container.right,/// Align the text in the center of the container.center,/// Stretch lines of text that end with a soft line break to fill the width of/// the container./// Lines that end with hard line breaks are aligned towards the [start] edge.justify,/// Align the text on the leading edge of the container./// For left-to-right text ([TextDirection.ltr]), this is the left edge./// For right-to-left text ([TextDirection.rtl]), this is the right edge.start,/// Align the text on the trailing edge of the container./// For left-to-right text ([TextDirection.ltr]), this is the right edge./// For right-to-left text ([TextDirection.rtl]), this is the left edge.end,}
其中 justinfy就是两边贴边对齐,start和end类似,差别是当文字方向是从右往左时会有些差别。
textDirection
文字方向,部分地区是从右往左排布。
softWrap
文本是否能换行,bool类型
overFlow
超出文本的表现形式,有三种枚举
enum TextOverflow {/// Clip the overflowing text to fix its container.clip,/// Fade the overflowing text to transparent.fade,/// Use an ellipsis to indicate that the text has overflowed.ellipsis,}
maxLines
指定文本最多显示多少行
textScaleFactor
字体缩放
Text.rich
通过TextSpan可以对部分文字进行修饰
new Text.rich(new TextSpan(text: '聆听璇律测试',children: <TextSpan>[new TextSpan(text: '测试1',style: new TextStyle(color: Colors.red)),new TextSpan(text: '哈哈',style: new TextStyle(color: Colors.yellow)),]))
以上就是Flutter中Text的基本使用。如有问题,欢迎指正。
