對比圖如下:左圖是默認的,右圖是自定義的(具體是什麼字體我也不清楚,百度隨便下載.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, //自定義字體
)),
);
}
}