如何使用自定義字體呢?如果是flutter 項(xiàng)目里集成或者flutter引用三方庫里的字體,flutter 文檔給出解決方案:https://flutterchina.club/custom-fonts/
但是如果字體是在SDCard 或者網(wǎng)絡(luò)上,我們應(yīng)該怎么做呢?
- 字體在服務(wù)器:
a) 我們可以使用FontLoader :
image.png
圖片地址:https://github.com/flutter/flutter/issues/17910#issuecomment-445184463
主要代碼:
image.png
b) 如果需要知道下載進(jìn)度怎么辦?
步驟1: 使用Dio 創(chuàng)建網(wǎng)絡(luò)請求,并獲取進(jìn)度, 結(jié)束后會(huì)自動(dòng)保存文件到指定目錄。

image.png
ps: dio 配置文檔 https://github.com/flutterchina/dio/blob/flutter/README-ZH.md
步驟2: 獲取保存到的本地文件。
-
字體在本地:
可以使用rootBundle 讀取指定文件:
image.png
然后就可以在TextStyle 使用剛才自定義名字的字體了。


