美文网首页
自学Flutter:默认的文本样式TextStyle

自学Flutter:默认的文本样式TextStyle

作者: android_coder | 来源:发表于2020-06-12 15:17 被阅读0次

本节主要是介绍文本样式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,
  })

支持的所有属性,当然我们可以只设置部分参数

3:运行结果

DAEAAA3D-41A8-41c7-92CC-B1903C906216.png

相关文章

网友评论

      本文标题:自学Flutter:默认的文本样式TextStyle

      本文链接:https://www.haomeiwen.com/subject/foogtktx.html