Aus öffentlichen Paketdaten erstellte Orientierung.
Das figma-Paket ist eine Dart-Bibliothek, die eine saubere, rein-Dart-Schnittstelle für die Figma-API bereitstellt und Entwicklern ermöglicht, programmgesteuert mit Figma-Dokumenten zu interagieren. Es unterstützt das Abrufen von Designdateien, das Abrufen von Assets und das Verwalten von Komponenten über mehrere Plattformen hinweg. Ideal zur Integration von Figma-Daten in Flutter-Apps oder -Tools, vereinfacht es Authentifizierung und Anfrageverarbeitung. Die Bibliothek wird aktiv gepflegt und ist kompatibel mit Android, iOS, Web, macOS, Windows und Linux.
Anwendungsfälle
Design-Dateien werden von Figma abgerufen
Design-Token in Apps synchronisieren
Automatisierung der Asset-Auswertung
Figma-Daten in CI/CD-Pipelines integrieren
Bauplanungs-Kooperationswerkzeuge
Hauptmerkmale
Reine Dart-Implementierung
Plattformübergreifende Unterstützung
Authentifizierungsverwaltung
Typsichere API-Antworten
Einfache Integration mit Flutter
Geeignet für
Flutter-Entwickler, die mit Figma arbeiten
Design-System-Werkzeuge
CI/CD-Workflows, die Design-Assets beinhalten
Teams automating design-to-code processes
Hinweise
Benötigt persönlichen Zugangstoken der Figma-API
Geschwindigkeitsbegrenzungen gelten für die Figma-API
Beschränkt auf öffentliche oder freigegebene Figma-Dateien, sofern nicht ordnungsgemäß autorisiert
Kein vollständiger Figma-Client, nur API-Interaktion
Original-README
Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.
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);