fontsource flutter
v0.4.0
輕鬆地將字體字體添加到flutter應用程序中。包括Fontsource API的DART接口。
首先,在fontsource鍵或fontsource.yaml文件下的pubspec.yaml文件中創建一個配置。
include : [my-package] # Defaults to all
fonts :
alex-brush : # This can be any font id
version : 4.5.3 # Defaults to latest
subsets : [latin, latin-ext] # Defaults to all
weights : [400] # Defaults to all
styles : [normal] # Defaults to all配置將告訴fontsource要下載的內容並將其捆綁到您的Flutter應用程序中。為了確保下載所有內容,請在修改配置後執行dart run fontsource 。另外,請確保每當您的存儲庫克隆時運行它。這將在.fontsource目錄中生成本地軟件包。
然後,您可以導入fontsource軟件包:
import 'package:fontsource/fontsource.dart' ;使用FontsourceTextStyle類使用Fontsource字體:
const Text (
'Hello world!' ,
style : FontsourceTextStyle (fontFamily : 'Alex Brush' , fontSize : 30 ),
), FontsourceTextStyle擴展了TextStyle類,因此可以使用任何樣式屬性來改變文本的外觀。
要在軟件包中使用它,請添加像普通的配置一樣,但不要運行Fontsource CLI。
具有Fontsource配置的軟件包將自動包含。要手動指定應該掃描哪些軟件包,請提供一個include鍵,其中包含要掃描的軟件包名稱列表。
Fontsource API還具有一個可以通過fontsource/api.dart訪問的DART接口。