figma_golden library

Figma Golden - Download PNG components from Figma for Flutter golden tests

This package provides a simple way to download components from Figma for use in Flutter golden tests. It automatically parses Figma links, downloads PNG images via Figma API and saves them to the required folder for testing.

Main function: downloadFigmaComponent

Usage examples:

import 'package:figma_golden/figma_golden.dart';

void main() {
  test('Download button component with explicit IDs', () async {
    // Method 1: Using explicit file and node IDs (most reliable)
    await downloadFigmaComponent(
      nodeData: FigmaNodeData(fileId: 'fileId', nodeId: '11:3359'),
      fileName: 'primary_button',
    );
  });

  test('Download button component from URL', () async {
    // Method 2: Creating from Figma URL (convenient for copy-paste)
    await downloadFigmaComponent(
      nodeData: FigmaNodeData.fromUrl('https://www.figma.com/design/fileId/Design?node-id=11-3359'),
      fileName: 'secondary_button',
    );
  });
}

Classes

FigmaGolden
Main class for downloading PNG images of components from Figma
FigmaGoldenConfig
Configuration class for Figma Golden package
FigmaNodeData
Data for Figma component containing file and node identifiers

Functions

downloadFigmaComponent({required FigmaNodeData? nodeData, required String fileName, String? relativePath, bool? forceDownload, Duration? timeout}) Future<void>
Downloads Figma component and saves it as PNG file for golden tests

Exceptions / Errors

FigmaApiException
Exception thrown when Figma API returns an error
FigmaDownloadTimeoutException
Exception thrown when download operation times out
FigmaFileException
Exception thrown when file operations fail
FigmaGoldenException
Base exception class for all Figma Golden related errors
FigmaNetworkException
Exception thrown when network operations fail
FigmaTokenException
Exception thrown when Figma API token is missing or invalid
FigmaUrlParseException
Exception thrown when URL parsing fails