fetchVariables method
Fetches all variables from the Figma file.
Makes an API request to fetch variables and their metadata. Returns the raw variable data from the API.
Throws an exception if:
- The API request fails
- The response is invalid
- The authentication token is invalid
Implementation
Future<Map<String, dynamic>> fetchVariables() async {
try {
final variablesUrl =
'${FigmaConstants.baseUrl}/files/$_fileId${FigmaConstants.variablesEndpoint}';
final response = await http.get(
Uri.parse(variablesUrl),
headers: {
FigmaConstants.authHeader: _figmaToken,
},
);
if (response.statusCode == 200) {
return json.decode(response.body);
} else {
throw Exception(
'${FigmaConstants.fetchVariablesError}: ${response.body}');
}
} catch (e) {
print('Error in fetchVariables: $e');
rethrow;
}
}