搜索插件、代码仓与 APP 分类

插件详情v7.5.0

figma

一个用于与 Figma 文档交互的 Figma API 包装库,使用纯 Dart 编写。

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 项

源码仓库

使用此插件的项目

暂无相关数据。