loadCustomFont function

Future<void> loadCustomFont(
  1. {required String name,
  2. required List<String> paths,
  3. bool isRelativePath = true}
)

Implementation

Future<void> loadCustomFont({
  required String name,
  required List<String> paths,
  bool isRelativePath = true,
}) async {
  const fs = LocalFileSystem();
  const platform = LocalPlatform();
  final Directory root = isRelativePath
      ? fs.currentDirectory
      : fs.directory(platform.environment['FLUTTER_ROOT']);

  final files = paths.map((path) => root.childFile(path)).toList();
  final fileName = name;

  final bytesList = files
      .map(
        (file) => Future<ByteData>.value(
          file.readAsBytesSync().buffer.asByteData(),
        ),
      )
      .toList();

  final fontLoader = FontLoader(fileName);
  bytesList.forEach((bytes) => fontLoader.addFont(bytes));

  await fontLoader.load();
}