fetchIcons function
Implementation
Future<List<ImgResult>> fetchIcons(
String key,
String token,
String ids,
CoreGenModel modelGen,
) async {
final headers = {'X-Figma-Token': token};
final dio = Dio();
dio.options.queryParameters = {
'ids': ids,
'format': modelGen.format,
'scale': modelGen.scale,
'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
.where((e) => e.key != null && e.key is String)
.map((e) => ImgResult(e.key!, e.value))
.toList();
return imgLst ?? <ImgResult>[];
} else {
stdout.writeln(response.statusMessage);
return [];
}
}