Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mr-1311/system_fonts
Load and use desktop system fonts with flutter apps
https://github.com/mr-1311/system_fonts
Last synced: 10 days ago
JSON representation
Load and use desktop system fonts with flutter apps
- Host: GitHub
- URL: https://github.com/mr-1311/system_fonts
- Owner: Mr-1311
- License: mit
- Created: 2024-05-07T00:38:48.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-05-12T20:36:24.000Z (9 months ago)
- Last Synced: 2024-05-12T21:35:29.434Z (9 months ago)
- Language: C++
- Homepage: https://pub.dev/packages/system_fonts
- Size: 3 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
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
1. Add the following line to your `pubspec.yaml` file in the `dependencies` section:
```yaml
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.
```dart
class Example extends StatefulWidget {
const Example({super.key});@override
State createState() => _ExampleState();
}class _ExampleState extends State {
String fontFamily = '';@override
void initState() {
super.initState();
SystemFonts().loadFont('arial').then((value) {
setState(() {
fontFamily = value.toString();
});
});
}@override
Widget build(BuildContext context) {
return Text('this text will use arial font', style: TextStyle(fontFamily: fontFamily));
}
}
```
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.
![](./assets/showcase.gif)
## License
This package is licensed under the MIT License. See the `LICENSE` file for details.