本节主要是介绍文本样式TextStyle的使用
1:代码示例
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
main() {
runApp(new MyDefaultText());
}
class MyDefaultText extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
title: "this is default text style",
home:Scaffold(
body:
Center(
child: DefaultTextStyle(
style: new TextStyle(color: Colors.red, fontSize: 26),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("我是第一个text"),
Text("我是第二个text"),
Text("我是第三个text",
//我们在使用每一个文本text的时候都可以为其创建一个TextStyle
style: new TextStyle(color: Colors.blue, fontSize: 22, height: 1.5)),
]
),
),
),
),
);
}
}
2:TextStyle解析
构造方法
const TextStyle({
this.inherit = true, this.color,this.backgroundColor,this.fontSize,
this.fontWeight, this.fontStyle,this.letterSpacing,this.wordSpacing,
this.textBaseline,this.height,this.locale,this.foreground,
this.background,this.shadows,this.fontFeatures,this.decoration,
this.decorationColor, this.decorationStyle,
this.decorationThickness,this.debugLabel,String fontFamily,
List<String> fontFamilyFallback,String package,
})
支持的所有属性,当然我们可以只设置部分参数
网友评论