// Get local variablesfinal localVars = await figma.getLocalVariables('file_key');
// Get published variablesfinal publishedVars = await figma.getPublishedVariables('file_key');
Component Management
// Get team componentsfinal teamComponents = await figma.getTeamComponents('team_id');
// Get component infofinal componentInfo = await figma.getComponent('component_id');
Comments and Collaboration
// Post a commentawait figma.postComment(
'file_key',
'This is a comment',
clientMetadata: {'key': 'value'}
);
// Get file commentsfinal comments = await figma.getComments('file_key');
Best Practices
Error Handling: The library throws FigmaException for API errors. Always implement proper error handling:
try {
final file = await figma.getFile('file_key');
} onFigmaExceptioncatch (e) {
print('Figma API error: ${e.message}');
}
Resource Management: When working with large files, request only the nodes you need:
// Instead of getting the entire filefinal specificNodes = await figma.getFileNodes(
'file_key',
['specific_node_id']
);
Rate Limiting: Implement appropriate rate limiting in your application to avoid hitting Figma's API limits.
Automation Examples
Export All Frame Images
Future<void> exportAllFrames(String fileKey) async {
final figma = FigmaClient('your_token');
final file = await figma.getFile(fileKey);
final frameIds = file.document.children
.whereType<Frame>()
.map((frame) => frame.id)
.toList();
final images = await figma.getImage(
fileKey,
frameIds,
format: 'png'
);
}
TypeScript/JavaScript Integration
When using this library in Flutter web projects that interact with JavaScript/TypeScript codebases:
// Dartfinal jsonData = await figma.getFile('file_key');
// Convert to JSON string for JS interopfinal jsonString = jsonEncode(jsonData);
// TypeScriptinterfaceFigmaFile {
// Your TypeScript type definitions
}
constfigmaData: FigmaFile = JSON.parse(jsonString);