figma 패키지는 Figma API에 대한 깔끔하고 순수한 Dart 인터페이스를 제공하는 Dart 라이브러리입니다. 개발자가 Figma 문서와 프로그래밍 방식으로 상호 작용할 수 있게 해줍니다. 디자인 파일을 가져오고, 자산을 검색하며, 여러 플랫폼에서 컴포넌트를 관리하는 것을 지원합니다. Flutter 앱이나 도구에 Figma 데이터를 통합하기에 적합하며, 인증 및 요청 처리를 간소화합니다. 이 라이브러리는 활발히 유지 보수되고 있으며 Android, iOS, Web, macOS, Windows, Linux와 호환됩니다.
사용 사례
Figma에서 디자인 파일을 가져오는 중
앱에서 디자인 토큰 동기화
자산 추출 자동화
CI/CD 파이프라인에 Figma 데이터 통합하기
건축 설계 협업 도구
주요 기능
순수한 다트 구현
크로스 플랫폼 지원
인증 처리
타입 안전한 API 응답
Flutter와의 간편한 통합
적합한 대상
Figma를 사용하는 Flutter 개발자
디자인 시스템 도구
디자인 자산을 포함하는 CI/CD 워크플로우
Teams automating design-to-code processes
고려 사항
Figma API 개인 액세스 토큰이 필요합니다
Figma API에 속도 제한이 적용됩니다
적절한 승인 없이 공개 또는 공유된 Figma 파일에 한정됨
완전한 Figma 클라이언트는 아니며, API 상호작용만 가능
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
figma
A library for interacting with Figma APIs with typed responses and data structures for working with Figma programatically.
Features
🚀 Full Figma API coverage with typed responses
🔒 Support for both API token and OAuth authentication
🔄 Support for variables (both local and published)
🛠️ Comprehensive component and style handling
📱 Export capabilities including PDF format
🧩 Support for component sets and variants
Installation
Add the package to your pubspec.yaml:
dependencies:figma:^7.3.4
Or install it using the Dart package manager:
dart pub add figma
Getting Started
Authentication
To use the Figma API, you'll need an access token. You can obtain one in two ways:
Personal Access Token: Generate from your Figma account settings
OAuth Token: Implement OAuth flow in your application
Basic Usage
import'package:figma/figma.dart';
voidmain() async {
// Initialize the client with your access tokenfinal figma = FigmaClient('your_access_token');
// Get a Figma filefinal file = await figma.getFile('file_key');
// Access file dataprint(file.name);
print(file.lastModified);
}
Working with Files
Retrieving File Information
// Get file with componentsfinal fileWithComponents = await figma.getFileWithNodes(
'file_key',
['node_id_1', 'node_id_2']
);
// Get file stylesfinal styles = await figma.getFileStyles('file_key');
// Get component setsfinal components = await figma.getFileComponentSets('file_key');
// 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);