remote_fonts 1.0.7 remote_fonts: ^1.0.7 copied to clipboard
Fetch and load remote fonts during Flutter app runtime. Also has ability to cache previously loaded fonts.
Features 💘 #
Fetch and load remote fonts during Flutter app runtime 💘 Also has ability to cache previously loaded fonts.
Getting started #
flutter pub add remote_fonts
Usage #
import 'package:remote_fonts/remote_fonts.dart';
import 'package:path_provider/path_provider.dart';
import 'package:flutter/material.dart';
import 'package:path/path.dart' as path;
RemoteFont _notoSansFont(Future<String> cacheDirPath) {
return RemoteFont(
family: 'NotoSans',
cacheDirPath: cacheDirPath, // Optional but required for caching to work
assets: [
const RemoteFontAsset(
'https://example.com/fonts/NotoSans/NotoSans-Regular.ttf',
// Optional but required for caching to work
'b9ba72dfa580114ddb2ccf06f93b31b1', // md5sum (or sha256sum) of font file
),
const RemoteFontAsset(
'https://example.com/fonts/NotoSans/NotoSans-Bold.ttf',
// Optional but required for caching to work
'5dd7fc028a59d98f1c87e58b70cc94077633ca0c33d2522c08985fee26334ee6', // sha256sum (or md5sum) of font file
),
],
);
}
class NiceText extends StatelessWidget {
const NiceText({super.key});
@override
Widget build(BuildContext context) {
final cacheDirPath = getTemporaryDirectory().then(
(tempDir) => path.join(tempDir.path, 'font_cache'),
);
final font = _notoSansFont(cacheDirPath);
font.load(); // No need to await the Future, fonts are automatically loaded to flutter engine
return Text(
'Some nice text',
style: TextStyle(fontFamily: font.family),
);
}
}