listFontMetadata function

Future<List<FontMetadata>> listFontMetadata({
  1. String? id,
  2. String? family,
  3. List<String>? subsets,
  4. List<int>? weights,
  5. List<String>? styles,
  6. String? defSubset,
  7. bool? variable,
  8. String? lastModified,
  9. String? category,
  10. String? version,
  11. String? type,
})

Returns a list of FontMetadatas.

Implementation

Future<List<FontMetadata>> listFontMetadata(
    {String? id,
    String? family,
    List<String>? subsets,
    List<int>? weights,
    List<String>? styles,
    String? defSubset,
    bool? variable,
    String? lastModified,
    String? category,
    String? version,
    String? type}) async {
  final query = {
    'id': id,
    'family': family,
    'subsets': subsets,
    'weights': weights?.map((weight) => weight.toString()),
    'styles': styles,
    'defSubset': defSubset,
    'variable': variable,
    'lastModified': lastModified,
    'category': category,
    'version': version,
    'type': type,
  };
  query.removeWhere((_, value) => value == null);
  final response = await http
      .get(Uri.parse('$apiUrl/v1/fonts?${Uri(queryParameters: query).query}'));
  List<dynamic> fonts = jsonDecode(response.body);

  return fonts.map((font) => FontMetadata.fromMap(font)).toList();
}