即一個單同樣式的文本 Text Widget就是顯示單同樣式的文本字符串。字符串可能會跨越多行,也可能所有顯示在同一行上,具體取決於佈局約束。html
style參數可選。若是省略了,文本將使用最近的DefaultTextStyle的樣式。若是給定樣式的TextStyle.inherit屬性爲true(默認值),則給定樣式將與最近的DefaultTextStyle合併。例如,好比能夠在使用默認字體系列和大小時使文本變爲粗體。app
const Text(this.data, {
Key key,
this.style,
this.strutStyle,
this.textAlign,
this.textDirection,
this.locale,
this.softWrap,
this.overflow,
this.textScaleFactor,
this.maxLines,
this.semanticsLabel,
}) : assert(data != null),
textSpan = null,
super(key: key);
複製代碼
style對文本的樣式,顏色,字體大小等有更加詳盡的定製,若是省略該參數則使用DefaultTextStyleless
const TextStyle({
this.inherit = true,
this.color,
this.fontSize,
this.fontWeight,
this.fontStyle,
this.letterSpacing,
this.wordSpacing,
this.textBaseline,
this.height,
this.locale,
this.foreground,
this.background,
this.shadows,
this.decoration,
this.decorationColor,
this.decorationStyle,
this.debugLabel,
String fontFamily,
List<String> fontFamilyFallback,
String package,
}) : fontFamily = package == null ? fontFamily : 'packages/$package/$fontFamily',
_fontFamilyFallback = fontFamilyFallback,
_package = package,
assert(inherit != null),
assert(color == null || foreground == null, _kColorForegroundWarning);
複製代碼
null
值替換爲祖先文本樣式中的值(例如,在TextSpan樹中)。若是爲false,則沒有顯式值的屬性將恢復爲默認值:白色,字體大小爲10像素,採用無襯線字體。textScaleFactor
來增長字體大小以便用戶更加方便的閱讀FontStyle.normal
(字體直立), FontStyle.italic
(字體傾斜)shadows: [Shadow(color:Colors.black,offset: Offset(6, 3), blurRadius: 10)]
, color
即陰影的顏色, offset
即陰影相對文本的偏移座標,blurRadius
即陰影的模糊程度,越小越清晰underline
下劃線, lineThrough
刪除線dashed
虛線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',
),
),
),
)
);
}
}
複製代碼