# network_font **Repository Path**: Spring_Cloud_Sell/network_font ## Basic Information - **Project Name**: network_font - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-05-15 - **Last Updated**: 2024-05-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 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](https://pub.dev/packages/google_fonts) and [cached_network_image](https://pub.dev/packages/cached_network_image) ## Getting Started ![](https://github.com/kithe-raker/network_font/blob/master/doc/example.gif) 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](https://pub.dev/packages/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. ![](https://github.com/kithe-raker/network_font/blob/master/doc/WorkFlow.png) ## How to use? 1️⃣ First step is to import `network_font` ```dart import 'package:network_font/network_font.dart'; ``` 2️⃣ Second step is to declare you network font's data ```dart final NetworkFont _networkFont = NetworkFont('family', url:'font_url'); ``` 3️⃣ Last step is to use `network_font`, there are 3 ways 1. NetworkFontText Widget ```dart NetworkFontText( 'NetworkFontText Widget', font: _networkFont, style: TextStyle(fontSize: 18), ), ``` 2. NetworkFont's style ```dart Text( 'NetworkFont Style', style: _networkFont.style(fontSize: 18), ), ``` 3. TextStyle *network_font* extension ```dart 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. ```dart 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 ```dart final DateTime _oneWeek = const Duration(days: 7); FontFunction.instance.setExpiredDuration(_oneWeek) ``` ***Note: You should call this before `initFont`*** ## Join flutter community 🌎 [Global FlutterDev Discord](https://discord.gg/rflutterdev) 🇹🇭 [Thailand Flutter Developer Group](https://www.facebook.com/groups/1330912973657674) 🇹🇭 [FlutterDevTH Discord](https://discord.gg/bU9F9c7kG9)