system_fonts 套件讓 Flutter 應用程式能夠存取並使用 Windows、macOS 與 Linux 上安裝的系統字型。它允許開發者動態載入使用者作業系統上已存在的字型,確保跨平台的一致性排版,而無需內建字型檔案。這對於需要原生類似文字呈現或想利用平台特定字型的應用程式特別有用。該套件支援跨平台開發,設定簡單。
適用情境
在桌面平台載入系統字型
使用原生排版創建應用
避免字體檔案捆綁
增強文字渲染的一致性
支援動態字體選擇
主要特色
跨平台支援(Windows、macOS、Linux)
系統字型的自動檢測
所需的設定最少
不需要包含字型資源
與 Flutter 的 TextStyle 集成
適合對象
桌面應用程式開發者
需要原生字型渲染的應用程式
專案中最小化資源大小
針對多個作業系統的開發人員
注重排版準確性的應用
使用建議
僅限系統安裝的字體
Android 或 iOS 上不可用
字型可用性取決於主機作業系統
可能無法與自訂或非標準字體一起使用
需要平台特定的測試
原始 README
以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。
system_fonts
A Flutter package that allows users to easily load system fonts on Windows, MacOS, and Linux platforms.
Features
Load system fonts dynamically in Flutter applications.
Support for Windows, MacOS, and Linux platforms.
Supports ttf and otf font formats.
Simple API for loading and using system fonts in your Flutter project.
Installation
Add the following line to your pubspec.yaml file in the dependencies section:
dependencies:system_fonts:^VERSION
Usage
Font family names are the font file name in the system without extensions.
For example to change font family of Text widget to arial(arial.ttf), use loadFont(String fontName) method with parameter arial,
this function will load arial.ttf file in the system and return font family name.
You can load all the fonts on the system with loadAllFonts() method which returns all the available font family names
and then you can use any font in any widget.
You can specify a font folder to load every font inside it and then use them in flutter with addAdditionalFontDirectory(String path) method.
You can add any font from full path with loadFontFromPath(String path) method.
You can list all available font family names to use with getFontList() method.
There is also a widget called SystemFontSelector() for list and select fonts and example app shows how to use it.
License
This package is licensed under the MIT License. See the LICENSE file for details.