Flutter——最详细的Text(文本)使用教程

Text(文本)简介

用于显示文字的组件。核心样式style属性控制

属性作用
styleTextStyle字体样式
textAlign文本对齐方式
textDirection文字的方向
overflow文本尾部显示的样式;
textScaleFactor文本大小比例
maxLines最大多少行

TextStyle文本样式属性:

属性作用
color文字颜色
backgroundColor背景颜色
fontSize字体大小
fontWeight字体粗细
fontStyle字体样式
letterSpacing字母间距
wordSpacing每个字间距
textBaseline文本基线
decoration添加上划线,下划线,删除线
decorationColor划线颜色
decorationStylestyle可能控制画实线,虚线,两条线,点, 波浪线等

创建一个红色文本

class TextWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      child: const Text(
        '字体大小字体大小字体大小字体大小字体大小字体大小字体大小',
        style: TextStyle(
        backgroundColor: Colors.blueAccent,
          color: Colors.red,
          fontSize: 20,
          fontWeight: FontWeight.w700,
          // letterSpacing: 20,
          textBaseline: TextBaseline.ideographic,
        ),
      ),
    );
  }
}

在这里插入图片描述

属性:==letterSpacing== 设置letterSpacing=10

在这里插入图片描述

很明显字体间距有所变化

属性:height: 2.0

        Text('height: 用在Text控件上的时候,会乘以fontSize做为行高,所以这个值不能设置过大',
              style: TextStyle(
                color: Colors.green,
                height: 2.0,
              )),

在这里插入图片描述

属性 decoration: TextDecoration.overline)

          Text('decoration: TextDecoration.overline 上划线',
              style: TextStyle(
                  color: Colors.red,
                  decoration: TextDecoration.overline,
                  fontSize: 20,
                  decorationStyle: TextDecorationStyle.wavy)),

在这里插入图片描述

属性: decoration: TextDecoration.lineThrough

        Text('decoration: TextDecoration.lineThrough 删除线',
              style: TextStyle(
                  fontSize: 20,
                  decorationColor: Colors.blueAccent,
                  decoration: TextDecoration.lineThrough,
                  decorationStyle: TextDecorationStyle.dashed)),

在这里插入图片描述

属性:decoration: TextDecoration.underline

          Text('decoration: TextDecoration.underline 下划线',
              style: TextStyle(
                  decorationColor: Colors.red,
                  fontSize: 20,
                  decoration: TextDecoration.underline,
                  decorationStyle: TextDecorationStyle.dotted)),

在这里插入图片描述

属性: wordSpacing: 15.0

          Text(
            'wordSpacing: 字或单词间距',
            style: TextStyle(
                fontSize: 20,
                // letterSpacing: 10.0,
                wordSpacing: 10.0),
          ),

在这里插入图片描述

属性:letterSpacing: 10.0

        Text(
            'letterSpacing: 字符间距',
            style: TextStyle(
              letterSpacing: 10.0,
              // wordSpacing: 15.0
            ),
          ),

在这里插入图片描述

属性:fontStyle: FontStyle.italic

      Text(
            'fontStyle: FontStyle.italic 斜体',
            style: TextStyle(
              fontStyle: FontStyle.italic,
            ),
          ),

在这里插入图片描述

属性:fontWeight: FontWeight.w700

          Text(
            'fontWeight: 字重',
            style: TextStyle(fontSize: 30, fontWeight: FontWeight.w700),
          ),

在这里插入图片描述

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

怀君

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值