initFont method Null safety

Future<void> initFont(
  1. NetworkFont fontData
)

Init fontData from network to your application.

This operation'll read font data from cache if it exists. Otherwise download from fontData.url and store it to cache.

Also This operation has unnecessary initialization checker, so call same fontData multiple-time does not repeated.

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

Implementation

Future<void> initFont(NetworkFont fontData) async {
  if (_initedFont.contains(fontData.family)) return;
  late final Future<ByteData> fontBytes = _getFontBytesData(fontData);

  final FontLoader font = FontLoader(fontData.family);
  font.addFont(fontBytes);
  await font.load();

  _initedFont.add(fontData.family);
}