fetchIcons function

Future<List<ImgResult>> fetchIcons(
  1. String key,
  2. String token,
  3. String ids
)

Implementation

Future<List<ImgResult>> fetchIcons(String key, String token, String ids) async {
  final headers = {'X-Figma-Token': token};
  final dio = Dio();
  dio.options.queryParameters = {
    'ids': ids,
    'format': 'svg',
    'use_absolute_bounds': true,
  };

  final response = await dio.request<dynamic>(
    'https://api.figma.com/v1/images/$key',
    options: Options(
      method: 'GET',
      headers: headers,
    ),
  );

  if (response.statusCode == 200) {
    final imgLst = FigmaImageResponse.fromJson(response.data)
        .images
        ?.entries
        .map((e) => ImgResult(e.key, e.value))
        .toList();
    return imgLst ?? <ImgResult>[];
  } else {
    stdout.writeln(response.statusMessage);
    return [];
  }
}