【自学Flutter】1.1 文本字体样式的使用

1.1 文本字体样式的使用

1.源代码

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget{
  @override
  Widget build(BuildContext context ){
    return MaterialApp(
      title:'Text widget usage',
      home:Scaffold(
        body:Center(
            child:Text('第一个Flutter程序!'* 5,
              textAlign: TextAlign.left,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              textScaleFactor: 1.5,
              style: TextStyle(
                fontSize: 20.0,
                color: Colors.blue,
                decoration: TextDecoration.underline,
                decorationColor: Color.fromARGB(120, 125, 20, 20),
                decorationStyle: TextDecorationStyle.solid,
                height: 1.2,
                fontFamily: "Courier",
                background: new Paint()..color=Colors.yellow
              ),
            ),
        ),
      ),
    );
  }
}

2.解释源代码

import 'package:flutter/material.dart';

//程序入口
void main () => runApp(MyApp()); 

//MyApp类
class MyApp extends StatelessWidget{

  //重写组件方法
  @override
  Widget build(BuildContext context ){
    return MaterialApp(  
	  //标题
      title:'Text widget usage',
	  //页面
      home:Scaffold(
		//主体
		//Center()居中方法
        body:Center(	
			//子组件
			//Text(文本内容) '*5表示内容重复5次'  文本组件
              child:Text('第一个Flutter程序!'* 5,
			  //文本对齐
              textAlign: TextAlign.left, 
              //最大行数
              maxLines: 1,
			  //溢出处理
              overflow: TextOverflow.ellipsis,
              //文本缩放
              textScaleFactor: 1.5,
			  //文本样式
			  //TextStyle() 文本样式处理方法
              style: TextStyle(
				//字体大小
                fontSize: 20.0,
                //字体颜色
                color: Colors.blue,
                //文本修饰(下划线...)
                decoration: TextDecoration.underline,
                //文本修饰颜色
                decorationColor: Color.fromARGB(120, 125, 20, 20),
                //文本修饰样式(虚线、点线...)
                decorationStyle: TextDecorationStyle.solid,
                //行高等于fontSize*height
                height: 1.2,
                //字体类型
                fontFamily: "Courier",
                //设置背景颜色
                background: new Paint()..color=Colors.yellow
              ),
            ),
        ),
      ),
    );
  }
}

猜你喜欢

转载自blog.csdn.net/weixin_43266090/article/details/93402649