getFontsAttributes function

List<FontAsset> getFontsAttributes(
  1. String fontsPath, {
  2. String? flavor,
})

Implementation

List<FontAsset> getFontsAttributes(
  String fontsPath, {
  String? flavor,
}) {
  final dir = Directory(fontsPath);
  if (!dir.existsSync()) {
    return [];
  }
  final files = dir.listSync().where((element) {
    return element is File &&
        ['.ttc', '.ttf', '.otf'].contains(extension(element.unixPath));
  });
  final grouped = groupBy(files, (s) {
    final parts = basenameWithoutExtension(s.unixPath).split('-');
    return parts.first;
  });
  return grouped.entries.map((e) {
    final family = e.key;
    return FontAsset(
      family: family,
      assets: e.value.map((f) => f.unixPath).toList(),
      flavor: flavor,
    );
  }).sortedBy((e) => e.family);
}