Text
文本默认是左对齐的。
-
textAlign
对齐方式,默认是左对齐-
TextAlign.left
左对齐 -
TextAlign.right
右对齐 -
TextAlign.center
居中对齐 -
TextAlign.justify
两端对齐 -
TextAlign.start
和阅读方式有关-
textDirection: TextDirection.ltr
和TextAlign.left
一致 -
textDirection: TextDirection.rtl
和TextAlign.right
一致
-
-
TextAlign.end
和TextAlign.start
正好相反
-
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,//显示省略号
/// Render overflowing text outside of its container.
visible,
}
RichText
可以通过给childen设置多个不同类型的TextSpan
实现富文本的效果。
class NormalTextWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return RichText(
text: TextSpan(text: "我最大", style: TextStyle(fontSize: 30,color: Colors.black), children: [
TextSpan(text: "No2", style: TextStyle(fontSize: 20)),
TextSpan(text: "No3", style: TextStyle(fontSize: 10))
]));
}
}