【Flutter】一、文本及字体样式
- 一、Text
-
- 1.1 Text构造方法
- 1.2属性说明
-
- 1.2.1 String data
- 1.2.2 TextStyle style
- 1.2.3 StrutStyle strutStyle
- 1.2.4 TextAlign textAlign
- 1.2.5 TextDirection textDirection
- 1.2.6 Locale locale
- 1.2.7 bool softWrap
- 1.2.8 TextOverflow overflow
- 1.2.9 double textScaleFactor
- 1.2.10 int maxLines
- 1.2.11 String semanticsLabel
- 1.2.12 TextWidthBasis textWidthBasis
- 1.3 示例代码
- 二、TextSpan
- 三、DefaultTextStyle
一、Text
用于显示文本。
Text(
'Hello world',
style: ...
);
1.1 Text构造方法
const Text(
this.data, {
Key key,
this.style,
this.strutStyle,
this.textAlign,
this.textDirection,
this.locale,
this.softWrap,
this.overflow,
this.textScaleFactor,
this.maxLines,
this.semanticsLabel,
this.textWidthBasis,
}) : assert(
data != null,
'A non-null String must be provided to a Text widget.',
),
textSpan = null,
super(key: key);
1.2属性说明
1.2.1 String data
要显示的文本信息
1.2.2 TextStyle style
设置文本样式(颜色、字体大小等)
TextStyle属性说明:
属性 | 说明 |
---|---|
bool inherit | 是否继承父节点样式,默认为true |
Color color | 设置字体颜色 例:Colors.green |
Color backgroundColor | 设置背景颜色 |
double fontSize | 设置字体大小 |
FontWeight fontWeight | 设置字体粗细 FontWeight.normal:默认,与w400一致 FontWeight.bold:加粗,与w700一致 FontWeight.w[100-900] |
FontStyle fontStyle | 设置字体样式: FontStyle.normal:正常 FontStyle.italic:斜体 |
double letterSpacing | 字母间间距 |
double wordSpacing | 单词间间距 |
TextBaseline textBaseline | 对齐文本的水平线 TextBaseline.alphabetic TextBaseline.ideographic |
double height | 文本行高 |
Locale locale | 根据地区以不同方式呈现 |
Paint foreground | 文本颜色,使用该属性时,color需为null Paint()..color = Colors.red |
Paint background | 文本背景色,使用该属性时,backgroundColor需为null |
TextDecoration decoration | TextDecoration.none: 默认 TextDecoration.lineThrough: 删除线 TextDecoration.underline: 下划线 TextDecoration.overline: 上划线 |
Color decorationColor | 控制decoration中产生线的颜色 |
TextDecorationStyle decorationStyle | 控制decoration中产生线的样式 TextDecorationStyle.solid: 实线 TextDecorationStyle.double: 双线 TextDecorationStyle.dotted: 点线 TextDecorationStyle.dashed: 虚线 TextDecorationStyle.wavy: 波浪线 |
double decorationThickness | 控制decoration产生线的粗细 |
String fontFamily | 设置文字字体 |
List<Shadow> shadows | 设置字体阴影 Shadow(color: Colors.black, offset: Offset(1.0, 1.0), blurRadius; 5.0) |
1.2.3 StrutStyle strutStyle
/// {@macro flutter.painting.textPainter.strutStyle}
final StrutStyle strutStyle;