सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।
figma पैकेज एक Dart लाइब्रेरी है जो Figma API के लिए एक साफ, शुद्ध-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);