即一个单同样式的文本 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',
),
),
),
)
);
}
}
复制代码