downloadFont function

Future<Uint8List> downloadFont(
  1. String url, {
  2. bool overwrite = false,
})

Implementation

Future<Uint8List> downloadFont(String url, {bool overwrite = false}) async {
  final uri = Uri.parse(url);
  final filename = uri.pathSegments.last;
  final dir = (await getApplicationSupportDirectory()).path;
  final file = File('$dir/$filename');

  if (await file.exists() && !overwrite) {
    return await file.readAsBytes();
  }

  final bytes = await downloadBytes(uri);
  file.writeAsBytes(bytes);
  return bytes;
}