文本字体样式

2020-01-15  本文已影响0人  spades_K
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(

        primarySwatch: Colors.red,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override  _MyHomePageState createState() => _MyHomePageState();

}

class _MyHomePageState extends State<MyHomePage> {
  
  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(

        title: Text(widget.title),
      ),

      body: Center(

        child: Column(
          children: <Widget>[

            Text(
              '来了 老弟 双击666 \n' * 6, // 重复字符串
              textAlign: TextAlign.center, // 居中
              textScaleFactor: 1.5, // 缩放因数 (个人理解放大比例)
              maxLines: 6, // 最大行数
              style: TextStyle( // 显示参数
                color: Colors.red,
                fontSize: 12,
                backgroundColor: Colors.yellow,
                decoration:TextDecoration.underline, // 下划线
                decorationStyle: TextDecorationStyle.dashed // 虚线
              ),

            ),
            Text(
              'TextOverflow.ellipsis,它会将多余文本截断后以省略符“...”表示;',
              style: Theme.of(context).textTheme.display1,
              overflow: TextOverflow.ellipsis, // 截断方式 这个是超出 ... 显示
              maxLines: 2,
            ),
            Text.rich(TextSpan(
              children: [
                TextSpan(
                  text: "标题:",
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 20,
                  ),
                ),
                TextSpan(
                  text: 'wwww.baidu.com',
                  style: TextStyle(
                    color: Colors.blue
                  )
                )
              ]
            )),  // 相当于富文本
            DefaultTextStyle( // 文本样式继承 相当于web 父标签样式子标签也继承
              style: TextStyle(
                color: Colors.cyan,
                backgroundColor: Colors.amber,
              ),
               child: Column(
                 children: <Widget>[
                   Text('啊啊啊啊啊'),
                   Text('哈哈哈哈哈哈哈'),
                 ],
               ),
            ),
          ],
        ),
      ),
    );
  }
}

效果图
上一篇 下一篇

猜你喜欢

热点阅读