Flutter开发之Text组件

Text

对一个APP而言文本无处不在,Text是进行Flutter开发最常用的组件之一。

Text常用的属性有哪些?

textAlign: TextAlign.center,//文本对齐方式
textDirection: TextDirection.ltr,//文本方向
overflow: TextOverflow.fade,//文字超出屏幕之后的处理方式(clip 裁剪,fade 渐隐,ellipsis 省略号)
textScaleFactor: 1.5,//double 字体显示倍率
maxLines: 6,//int 文字显示最大行数

其中style属性是一个对象:
style: TextStyle(
color: Colors.red,//字体颜色
fontSize: 14,//字体大小
fontWeight: FontWeight.normal,//字重
fontStyle: FontStyle.italic,//文字样式(italic 斜体,normal 正常体)
backgroundColor: Colors.amber.withOpacity(0.3),//文本背景颜色
decoration: TextDecoration.lineThrough,//文字装饰线(none 没有线,lineThrough 删除线,overline 上划线,underline 下划线)
decorationColor: Colors.black,//文字装饰线颜色
decorationStyle: TextDecorationStyle.wavy,//文字装饰线风格([dashed,dotted]虚线, double 两根线,solid 一根实线,wavy 波浪线)
decorationThickness: 3.0, //字体的基本笔划厚度/宽度
wordSpacing: 100.0,//单词(英文单词或汉语词语)间隙(如果是负值,会让单词变得更紧凑)
letterSpacing: 20,//字符(单个字母或汉字)间隙(如果是负值,会让字母变得更紧凑)

其中,需要注意的是:

wordSpacing: 100.0,//单词间隔100pixels
是指单词(英文单词或汉语词语)间隙(如果是负值,会让单词变得更紧凑)

letterSpacing: 20,//单个字符间隔20pixels
是指字符(单个字母或汉字)间隙(如果是负值,会让字母变得更紧凑)

demo

测试效果:


Flutter开发之Text组件_第1张图片
image.png

测试代码:

class MyHome extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text(
        'A negative value can be used 哈哈哈哈 哈哈啊,, to bring the words closer',
        textAlign: TextAlign.center,//文本对齐方式
        textDirection: TextDirection.ltr,//文本方向
        overflow: TextOverflow.fade,//文字超出屏幕之后的处理方式(clip 裁剪,fade 渐隐,ellipsis 省略号)
        textScaleFactor: 1.5,//double 字体显示倍率
        maxLines: 6,//int 文字显示最大行数
        style: TextStyle(
          color: Colors.red,//字体颜色
          fontSize: 14,//字体大小
          fontWeight: FontWeight.normal,//字重
          fontStyle: FontStyle.italic,//文字样式(italic 斜体,normal 正常体)
          backgroundColor: Colors.amber.withOpacity(0.3),//文本背景颜色
          decoration: TextDecoration.lineThrough,//文字装饰线(none 没有线,lineThrough 删除线,overline 上划线,underline 下划线)
          decorationColor: Colors.black,//文字装饰线颜色
          decorationStyle: TextDecorationStyle.wavy,//文字装饰线风格([dashed,dotted]虚线, double 两根线,solid 一根实线,wavy 波浪线)
          // decorationThickness: 3.0, //字体的基本笔划厚度/宽度
          wordSpacing: 100.0,//单词(英文单词或汉语词语)间隙(如果是负值,会让单词变得更紧凑)
          letterSpacing: 20,//字符(单个字母或汉字)间隙(如果是负值,会让字母变得更紧凑)
        ),//字体样式
      ),
    );
  }
}

参考:
https://api.flutter.dev/flutter/painting/TextStyle-class.html

你可能感兴趣的:(Flutter开发之Text组件)