一肄满、Text組件屬性
Text("Hello world",
textAlign: TextAlign.left,//文本對齊方式 (center居中谴古,left左對齊,right右對齊稠歉,justfy兩端對齊)
textDirection: TextDirection.ltr,//文本方向 (ltr從左至右掰担,rtl從右至左)
maxLines: 1,//最大行數(shù)
softWrap: true,//是否自動換行 (true自動換行,false不換行怒炸,超出屏幕部分默認截斷處理)
overflow: TextOverflow.clip,//文字超出屏幕之后的處理方式 (clip裁剪带饱,fade漸隱,ellipsis省略號)
textScaleFactor: 1.5,//字體顯示倍率
style: TextStyle(//文字樣式
color: Colors.blue,//文字顏色 (十六進制顏色寫法Color(0xff4caf50)數(shù)字0字母xff后跟十六進制代碼 0xff中ff代表透明度)
fontSize: 18.0,//文字大小
height: 1.2, //指定行高
fontStyle: FontStyle.italic,//文字樣式 (italic斜體阅羹,normal正常體)
fontFamily: "Courier",//字體
fontWeight: FontWeight.w900,//文字粗細
background: Paint()..color=Colors.yellow,
decoration:TextDecoration.none,//文字裝飾線 (none沒有線勺疼,lineThrough刪除線,overline上劃線捏鱼,underline下劃線)
decorationStyle: TextDecorationStyle.dashed//文字裝飾線風格 ([dashed,dotted]虛線执庐,double兩根線,solid一根實線导梆,wavy波浪線)
),
);
二轨淌、Text片段
- 如果我們需要對一個 Text 內(nèi)容的不同部分按照不同的樣式顯示,這時就可以使用TextSpan看尼,它代表文本的一個“片段”递鹉。
Text.rich(TextSpan(
children: [
TextSpan(
text: "Home: "
),
TextSpan(
text: "https://flutterchina.club",
style: TextStyle(
color: Colors.blue
),
recognizer: _tapRecognizer
),
]
));
三藏斩、設置默認樣式
- 在 Widget 樹中躏结,文本的樣式默認是可以被繼承的(子類文本類組件未指定具體樣式時可以使用 Widget 樹中父級設置的默認樣式),因此狰域,如果在 Widget 樹的某一個節(jié)點處設置一個默認的文本樣式萍启,那么該節(jié)點的子樹中所有文本都會默認使用這個樣式
DefaultTextStyle(
//設置文本默認樣式
style: TextStyle(
color:Colors.red,
fontSize: 20.0,
),
textAlign: TextAlign.start,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("hello world"),
Text("I am Jack"),
Text("I am Jack",
style: TextStyle(
inherit: false, //2.不繼承默認樣式
color: Colors.grey
),
),
],
),
);