flutter学习四:使用自定义字体

对比图如下:左图是默认的,右图是自定义的(具体是什么字体我也不清楚,百度随便下载.ttf文件的) 

                                           

 操作步骤如下(前提有ttf文件):

一.根目录下建立fonts文件夹,把ttf文件放进去,如下图所示:

二.pubspec.yaml(原本是fonts:……只是注释掉了,我没有动它原来的,自己写了)

三.使用

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class HomeScreen extends StatelessWidget {
  final textStyle = const TextStyle(
    fontFamily: 'Chu',
    color: Colors.red,
    fontSize: 20,
  );

  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('首页'),
      ),
      body: new Center(
          child: new Text(
        '我是Home界面',
//        style: TextStyle(color: Colors.red, fontSize: 20),//默认字体
        style: textStyle, //自定义字体
      )),
    );
  }
}
发布了65 篇原创文章 · 获赞 11 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_40420578/article/details/104020074