Flutter-Text组件

本文详细介绍了Flutter中Text组件的使用方法及其属性设置,包括文本对齐、溢出处理、最大行数限制等,并通过示例代码展示了如何设置文本样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
          )
        ),
      ),
    );
  }
}

效果如下:
Text

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值