network_font 0.0.4 icon indicating copy to clipboard operation
network_font: ^0.0.4 copied to clipboard

network_font will help you use your custom font from network, so you don't have to store those fonts in your project directory's asset folder.

network_font #

Help you easily uses font from network ๐Ÿ’ช

In case you want user to use a plenty of custom font from network, This network_font package will help you use your custom font from network, so you don't have to store those fonts in your project directory's asset folder.

Also this package is inspired by google_fonts and cached_network_image

Getting Started #

This network_font package will help you use your custom font from network, so you don't have to store in asset folder in the project directory.

How it work? #

Basically just like cached_network_image. If your font file from network isn't exists in user's cache directory or expired, this package'll download and store your fontย to user's cache directory.

How to use? #

1๏ธโƒฃ First step is to import network_font

import 'package:network_font/network_font.dart';

2๏ธโƒฃ Second step is to declare you network font's data

final NetworkFont _networkFont = NetworkFont('family', url:'font_url');

3๏ธโƒฃ Last step is to use network_font, there are 3 ways

  1. NetworkFontText Widget

     NetworkFontText(
         'NetworkFontText Widget',
         font: _networkFont,
         style: TextStyle(fontSize: 18),
     ),
    
  2. NetworkFont's style

     Text(
         'NetworkFont Style',
         style: _networkFont.style(fontSize: 18),
     ),
    
  3. TextStyle network_font extension

     Text(
         'NetworkFont Extension',
         style: TextStyle(fontSize: 18).network(_networkFont),
     ),
    

    However there are no different in technical, only code style that's different ๐Ÿ„โ€โ™‚๏ธ

Other function #

initFont #

allow you to init font from network to your application.

This function'll read font data from cache. But If font data doesn't exist or expired, this function'll download from fontData.url and store it to user's cache directory.

Also This operation has unnecessary initialization checker to, so call initFont on same fontData multiple-time will not repeated.

import 'package:network_font/network_font.dart';
.
.
final NetworkFont _networkFont = NetworkFont('family', url:'font_url');

@override
void initState() {
  FontFunction.instance.initFont(_networkFont);
  super.initState();
}

@override
Widget build(BuildContext context) {
  return Text(
        'Example Text',
        style: TextStyle(fontFamily: fontFamily: _networkFont.family),
    );
}

Note: Currently only support OpenType (OTF) and TrueType (TTF) fonts.

setExpiredDuration #

Set expired duration of cached font.

Default is 30 days

final DateTime _oneWeek = const Duration(days: 7);

FontFunction.instance.setExpiredDuration(_oneWeek)

Note: You should call this before initFont

Join flutter community #

๐ŸŒŽ Global FlutterDev Discord

๐Ÿ‡น๐Ÿ‡ญ Thailand Flutter Developer Group

๐Ÿ‡น๐Ÿ‡ญ FlutterDevTH Discord

7
likes
110
pub points
29%
popularity

Publisher

unverified uploader

network_font will help you use your custom font from network, so you don't have to store those fonts in your project directory's asset folder.

Homepage

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

flutter, hive, http, path_provider

More

Packages that depend on network_font