- 将字体放入assets/fonts下
-
在pubspec.yaml文件中flutter下添加如下代码:
flutter:
fonts:
- family: MyCustomFont
fonts:
- asset: assets/fonts/MyCustomFont.ttf -
在flutter Text widget中使用字体
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('自家字体使用'),
),
body: Center(
child: Text(
'我是自家字体',
style: TextStyle(fontFamily: 'MyCustomFont'),
),
),
),
);
}
}