本文学习在程序中使用自定义字体
https://fonts.google/?selection.family=Hanalei+Fill (有很多字体供选择)需翻墙,这里我们随便下载了一下用来演示

如果你没有字体可以用,可以去下载我的字体,飞机票

在使用字体之前我们需要做一些准备工作
1.在项目的根目录创建一个文件夹用来放字体文件

2.在pubspec.yaml文件中添加如下:

代码中使用:

import 'package:flutter/material.dart';

void main() => runApp(new MaterialApp(
      title: "Flutter Weather",
      home: new MyApp(),
    ));

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var home = new Scaffold(
      appBar: new AppBar(
        title: new Text("Flutter Font"),
      ),
      body: new Center(
        child: new Text("duo_shine@163",style: const TextStyle(fontFamily: "HanaleiFill"),),
      ),
    );
    return home;
  }
}

运行:

更多推荐

Flutter的菜鸟教程二十五:Flutter字体