Flutter基础控件:Text

@TOCText
单一格式文本

属性

style

文本样式,类型是TextStyle

strutStyle

Strut是一项允许设置最小线高的功能。 效果就像该段落的每一行的开头都包含一个零宽度的空间。

textAlign

文本的对齐方式,类型是TextAlign

center: 文本居中对齐
left: 文本左对齐
right: 文本右对齐
start: 文本开始位置对齐,类似左对齐
end: 文本结束位置对齐,类似右对齐
justify: 文本两端对齐

textDirection

文本方向,即文字从那边开始显示。类型是TextDirection

locale

国际化相关。选择用户语言和格式的标识符,类型是Locale

softWrap

是否自动换行。
false标识文本只有一行,水平方向无限。true本内容超过一行后可以换行显示。同时设置softWrap和overflow属性时,overflow具有更高优先级

overflow

溢出文本如何处理,同时设置overflow和maxLines属性时,maxLines具有更高优先级

类型是TextOverflow
TextOverflow.visible:自动换行显示
TextOverflow.clip:尾部直接截断
TextOverflow.ellipsis:尾部显示省略号
TextOverflow.fade: 溢出的部分会进行一个渐变消失的效果,softWrap 属性为 false 时才会有效果。

textScaleFactor

double类型 表示文本相对于当前字体的缩放因子,默认为1.0

maxLines

int 类型,文本最大行数

semanticsLabel

给文本加上一个语义标签,没有实际用处

textWidthBasis

一行或多行文本宽度的不同方式,类型是TextWidthBasis

例子

    Text("嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔嗨,煞笔",
        style: TextStyle(color: Colors.red,
          fontSize: 21,
          maxLines: 2,
          textAlign: TextAlign.start,
          background: Paint()..color = Colors.yellow),
      )

TextStyle

const TextStyle({ 
    this.inherit = true, //是否继承父Text的样式,默认为true
    this.color,  //文字的颜色 类型为Color
    this.backgroundColor,  //背景颜色 类型为Color
    this.fontSize, //double 类型,文字的大小 
    this.fontWeight, //字体粗细,类型是FontWeight
    this.fontStyle, //是否在字体中倾斜字形,类型为FontStyle
    this.letterSpacing, // double类型,字母之间的间隔 
    this.wordSpacing, //double类型,单词之间的间隔
    this.textBaseline, //用于对齐文本的水平线,类型是 TextBaseline
    this.height, //double类型,文本的高度,但它并不是一个绝对值,而是一个因子,具体的行高等于fontSize*height。
    this.locale, //选择用户语言和格式的标识符,类型是Locale
    this.foreground,//文本的前景色,类型是Paint
    this.background,//文本的背景色    ,类型是Paint
    this.shadows,//在文本下方绘制阴影,类型是List< ui.Shadow>
    this.fontFeatures,//字体选择字形的列表,类型List<ui.FontFeature>     
    this.decoration,//文本的线条,类型是TextDecoration   
    this.decorationColor,//TextDecoration 线条的颜色,类型是Color
    this.decorationStyle,//TextDecoration 线条的样式,类型是TextDecorationStyle
    this.decorationThickness,//double类型,默认为1.0,表示使用字体的基本画笔厚度宽度
    this.debugLabel,//String 类型,文本样式的描述无实际用处
    String fontFamily,//String类型,用于设置使用哪种自定义字体
    List<String> fontFamilyFallback,//String 类型,字体列表,当前面的字体找不到时,会在这个列表里依次查找
    String package,//String 类型,用于设置使用哪种自定义字体
  })

TextDecorationStyle

enum TextDecorationStyle {
solid,//一条实线
double, //两条线
dotted, //一条点画线
dashed, // 一条短横线虚线
wavy // 一条波浪线
}

import 'package:flutter/material.dart';
void main() => runApp(MyApp());
// Text详解
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter_Wieghts',
      home: Scaffold(
        appBar: AppBar(
        title: Text('Text Learn'),
      ),
      body: Center(
        child: Text('Hello World'*4,
        style: TextStyle(
          inherit: true,
          color: Colors.white,
          fontSize: 30.0,
          fontWeight: FontWeight.w400,
          fontStyle: FontStyle.italic,
          letterSpacing: 5,
          wordSpacing: 20,
          textBaseline: TextBaseline.alphabetic,
          height: 1.2,
          locale: Locale('fr', 'CH'),
          background: Paint() ..color = Colors.blue,
          shadows: [Shadow(color:Colors.black,offset: Offset(6, 3), blurRadius: 10)],
          decoration: TextDecoration.underline,
          decorationColor: Colors.black54,
          decorationStyle: TextDecorationStyle.dashed,
          debugLabel: 'test',
        ),
        ),
       ),
      )
    );
  }
}
 

引用

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值