Skip to content

Fetch and load remote fonts during Flutter app runtime ๐Ÿ’˜ Also has ability to cache previously loaded fonts.

License

Notifications You must be signed in to change notification settings

giriss/remote_fonts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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

Screenshot

Example screenshot

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
        // md5sum (or sha256sum) of font file
        'b9ba72dfa580114ddb2ccf06f93b31b1',
      ),
      const RemoteFontAsset(
        'https://example.com/fonts/NotoSans/NotoSans-Bold.ttf',

        // Optional but required for caching to work
        // sha256sum (or md5sum) of font file
        '5dd7fc028a59d98f1c87e58b70cc94077633ca0c33d2522c08985fee26334ee6',
      ),
    ],
  );
}

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);
    RemoteFontsLoader.load([font]); // No need to await the Future, fonts are
                                    // automatically loaded to flutter engine

    return Text(
      'Some nice text',
      style: TextStyle(fontFamily: font.family),
    );
  }
}

About

Fetch and load remote fonts during Flutter app runtime ๐Ÿ’˜ Also has ability to cache previously loaded fonts.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published