Created
November 27, 2020 19:53
-
-
Save smolck/eb1473c4b11a6ab4d761a0531efe375a to your computer and use it in GitHub Desktop.
Loading fonts at runtime in Dart/Flutter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:io'; | |
import 'package:flutter/services.dart'; | |
Future<ByteData> getFont() async { | |
var bytes = await File('${Platform.environment['HOME']}/.local/share/fonts/path/to/font}').readAsBytes(); | |
return ByteData.sublistView(bytes); | |
} | |
void main() async { | |
var fontLoader = FontLoader('SomeFontFamily')..addFont(getFont()); | |
await fontLoader.load(); | |
// Call the usual Flutter `runApp(...)` here. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment