搜尋套件、儲存庫與 APP 分類

套件詳情v7.5.0

figma

一個用純 Dart 編寫的 Figma API 包裝程式庫,用於與 Figma 文件互動。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
2040
喜歡數
25
Pub 分數
130

安裝套件

flutter pub add figma

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

figma 套件是一個 Dart 庫,為 Figma API 提供乾淨、純 Dart 的介面,讓開發者能以程式化方式與 Figma 文件互動。它支援取得設計檔案、取得資源,以及在多個平台管理元件。非常適合將 Figma 資料整合至 Flutter 應用程式或工具中,簡化驗證與要求處理。此套件持續維護,並相容於 Android、iOS、Web、macOS、Windows 及 Linux。

適用情境

  • 從 Figma 取得設計檔案
  • 在應用中同步設計令牌
  • 自動化資產提取
  • 將 Figma 數據整合到 CI/CD 流水線中
  • 建築設計協作工具

主要特色

  • 純 Dart 實現
  • 跨平台支援
  • 身份驗證處理
  • 類型安全的 API 回應
  • 與 Flutter 的輕鬆整合

適合對象

  • 使用 Figma 的 Flutter 開發人員
  • 設計系統工具
  • 涉及設計資產的 CI/CD 工作流程
  • Teams automating design-to-code processes

使用建議

  • 需要 Figma API 個人訪問令牌
  • Figma API 上應用了速率限制
  • 除非獲得適當授權,否則僅限公開或共用的 Figma 檔案
  • 不是完整的 Figma 客戶端,僅支援 API 互動

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

figma

Dart CI pub license

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:

  1. Personal Access Token: Generate from your Figma account settings
  2. OAuth Token: Implement OAuth flow in your application
Basic Usage
import 'package:figma/figma.dart';

void main() async {
  // Initialize the client with your access token
  final figma = FigmaClient('your_access_token');
  
  // Get a Figma file
  final file = await figma.getFile('file_key');
  
  // Access file data
  print(file.name);
  print(file.lastModified);
}

Working with Files

Retrieving File Information
// Get file with components
final fileWithComponents = await figma.getFileWithNodes(
  'file_key',
  ['node_id_1', 'node_id_2']
);

// Get file styles
final styles = await figma.getFileStyles('file_key');

// Get component sets
final components = await figma.getFileComponentSets('file_key');
Working with Images
// Export images
final images = await figma.getImage(
  'file_key',
  ['node_id'],
  format: 'png',
  scale: 2
);

// Get image fills
final imageFills = await figma.getImageFills(['image_ref_1', 'image_ref_2']);

Advanced Features

Variables Support
// Get local variables
final localVars = await figma.getLocalVariables('file_key');

// Get published variables
final publishedVars = await figma.getPublishedVariables('file_key');
Component Management
// Get team components
final teamComponents = await figma.getTeamComponents('team_id');

// Get component info
final componentInfo = await figma.getComponent('component_id');
Comments and Collaboration
// Post a comment
await figma.postComment(
  'file_key',
  'This is a comment',
  clientMetadata: {'key': 'value'}
);

// Get file comments
final comments = await figma.getComments('file_key');

Best Practices

  1. Error Handling: The library throws FigmaException for API errors. Always implement proper error handling:

    try {
      final file = await figma.getFile('file_key');
    } on FigmaException catch (e) {
      print('Figma API error: ${e.message}');
    }
    
  2. Resource Management: When working with large files, request only the nodes you need:

    // Instead of getting the entire file
    final specificNodes = await figma.getFileNodes(
      'file_key',
      ['specific_node_id']
    );
    
  3. 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:

// Dart
final jsonData = await figma.getFile('file_key');
// Convert to JSON string for JS interop
final jsonString = jsonEncode(jsonData);
// TypeScript
interface FigmaFile {
  // Your TypeScript type definitions
}

const figmaData: FigmaFile = JSON.parse(jsonString);

Resources

Contributing

Contributions are welcome! Please read our contributing guidelines and submit pull requests to our GitHub repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

所屬分類

依賴

依賴清單 6 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。