Text组件
参考:
其构造方法
const Text(
String data,
{Key key,
TextStyle style,
StrutStyle strutStyle,
TextAlign textAlign,
TextDirection textDirection,
Locale locale,
bool softWrap,
TextOverflow overflow,
double textScaleFactor,
int maxLines,
String semanticsLabel,
TextWidthBasis textWidthBasis,
TextHeightBehavior textHeightBehavior}
)
textAlign
- 文本的对齐方式maxLines
- 最大行数overflow
- 截断方式textScaleFactor
- 缩放因子
TextStyle
用于指定文本显示的样式如颜色、字体、粗细、背景等。参考:
如下的代码,设置Text
的样式
class HomeContent extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Container(
child: Text(
'一个文本' * 10,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
maxLines: 2,
style: TextStyle(
fontSize: 20.0,
color: Colors.red,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic,
decoration: TextDecoration.lineThrough, //删除线
decorationColor: Colors.green,
decorationStyle: TextDecorationStyle.dashed, //虚线
),
),
height: 300.0,
width: 300.0,
decoration: BoxDecoration(
color: Colors.yellow,
border: Border.all(
color: Colors.blue,
width: 2.0
)
),
),
);
}
}
效果如下: