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

套件詳情v2.0.1

widgets_to_image

一個強大的 Flutter 套件,可將任何小部件轉換為高品質影像,支援自訂格式、品質設定與進階功能。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
2.6萬
喜歡數
225
Pub 分數
160

安裝套件

flutter pub add widgets_to_image

套件介紹

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

widgets_to_image 是一個 Flutter 套件,讓開發者能夠將任何 widget 轉換為高品質影像,支援多種格式、可自訂的品質設定與進階渲染選項。非常適合在應用程式內直接產生截圖、預覽或可匯出的資源。此套件可在 Android、iOS、Web、macOS、Windows 與 Linux 等所有主要平台運作,使它在跨平台專案中極具彈性。透過簡單的 API,能輕鬆整合至測試流程、UI 預覽與動態內容產生。

適用情境

  • 程式化產生應用截圖
  • 在開發中建立 UI 預覽
  • 匯出小部件為影像以分享
  • 自動化測試與視覺驗證
  • 在Flutter應用中建構建築設計工具

主要特色

  • 支援多種影像格式
  • 可自訂的影像品質與大小
  • 跨平台相容性
  • 與現有組件的輕鬆整合
  • 進階渲染選項,例如背景顏色和內邊距

適合對象

  • 開發使用者介面預覽工具的開發者
  • 需要自動化截圖生成的團隊
  • 需要動態影像匯出的應用
  • 測試自動化工程師
  • 注重設計的 Flutter 應用程式

使用建議

  • 渲染複雜組件時的性能影響
  • 大尺寸或高解析度影像的記憶體使用情況
  • 需要正確處理異步渲染
  • 僅限靜態圖像輸出(無動畫)
  • 可能需要特定平台的設定才能獲得最佳效果

原始 README

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

Widgets To Image

pub package License: MIT Demo

A powerful Flutter package to convert any widget into high-quality images with customizable formats, quality settings, and advanced features.

🌐 Live Demo

Try the interactive demo →

Experience the package capabilities with our modern, professional demo featuring:

  • 🎯 Basic widget capture examples
  • ⚙️ Advanced configuration options
  • 🎭 Animation capture demonstrations
  • 📱 Responsive design with Material 3

Demo

✨ Features

  • 🎯 Simple API - Convert any widget to image with just a few lines of code
  • 🖼️ Multiple Formats - Support for PNG, JPEG, Raw RGBA, and Raw Unmodified formats
  • ⚙️ Customizable Options - Control pixel ratio, quality, animations, and delays
  • 🎨 High Quality - Generate high-resolution images with custom pixel ratios
  • 🔄 Animation Support - Capture animated widgets with proper timing
  • 📱 Cross Platform - Works on iOS, Android, Web, macOS, Windows, and Linux
  • 🧪 Well Tested - Comprehensive test suite ensuring reliability
  • 📚 Rich Documentation - Detailed examples and API documentation

🚀 Getting Started

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  widgets_to_image: ^2.0.0

Install it using the command line:

flutter pub get

Import the package:

import 'package:widgets_to_image/widgets_to_image.dart';

📖 Usage

Basic Usage
// Create a controller
WidgetsToImageController controller = WidgetsToImageController();

// Wrap your widget
WidgetsToImage(
  controller: controller,
  child: Container(
    width: 200,
    height: 100,
    color: Colors.blue,
    child: const Center(
      child: Text(
        'Hello World!',
        style: TextStyle(color: Colors.white, fontSize: 20),
      ),
    ),
  ),
)

// Capture the widget
Uint8List? bytes = await controller.capture();
Advanced Usage with Options
// Capture with custom options
Uint8List? bytes = await controller.capture(
  options: const CaptureOptions(
    format: ImageFormat.jpeg,
    pixelRatio: 3.0,
    quality: 95,
    waitForAnimations: true,
    delayMs: 100,
  ),
);
Convenience Methods
// Capture as PNG with high resolution
Uint8List? pngBytes = await controller.capturePng(
  pixelRatio: 3.0,
  waitForAnimations: true,
);

// Capture as JPEG with custom quality
Uint8List? jpegBytes = await controller.captureJpeg(
  quality: 90,
  pixelRatio: 2.0,
);
Reactive UI with Builder
WidgetsToImageBuilder(
  controller: controller,
  builder: (context, isCapturing, capture) {
    return Column(
      children: [
        if (isCapturing)
          const CircularProgressIndicator()
        else
          ElevatedButton(
            onPressed: () async {
              final bytes = await capture();
              // Handle the captured bytes
            },
            child: const Text('Capture Widget'),
          ),
      ],
    );
  },
)
Error Handling
try {
  final bytes = await controller.capture();
  // Success - use the bytes
} on CaptureException catch (e) {
  // Handle specific capture errors
  print('Capture failed: ${e.message}');
  if (e.originalError != null) {
    print('Caused by: ${e.originalError}');
  }
} catch (e) {
  // Handle other errors
  print('Unexpected error: $e');
}
Lifecycle Callbacks
controller.onCaptureStart = () {
  print('Capture started');
};

controller.onCaptureComplete = (bytes) {
  print('Capture completed with ${bytes.length} bytes');
};

controller.onCaptureError = (error) {
  print('Capture failed: ${error.message}');
};

🔧 API Reference

CaptureOptions
Property Type Default Description
pixelRatio double 1.0 The pixel ratio for the captured image
format ImageFormat ImageFormat.png The output image format
quality int 95 Quality for JPEG format (0-100)
waitForAnimations bool false Wait for animations before capturing
delayMs int 0 Additional delay in milliseconds
ImageFormat
  • ImageFormat.png - PNG format with transparency support
  • ImageFormat.jpeg - JPEG format with quality control
  • ImageFormat.rawRgba - Raw RGBA pixel data
  • ImageFormat.rawUnmodified - Raw unmodified pixel data
WidgetsToImageController Methods
  • capture({CaptureOptions options}) - Capture with custom options
  • capturePng({...}) - Convenience method for PNG capture
  • captureJpeg({...}) - Convenience method for JPEG capture
  • dispose() - Clean up resources
WidgetsToImage Properties
  • controller - The capture controller (required)
  • child - The widget to capture
  • clipBehavior - Whether to clip the child widget

📱 Example App

The package includes a comprehensive example app demonstrating:

  • Basic widget capture
  • Advanced options configuration
  • Animated widget capture
  • Different image formats
  • Error handling
  • Reactive UI updates

Run the example:

cd example
flutter run

🛠️ Platform Support

Platform Support
Android ✅
iOS ✅
Web ✅
macOS ✅
Windows ✅
Linux ✅

🤝 Contributing

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

📄 License

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

🙏 Acknowledgments

  • Flutter team for the amazing framework
  • Community contributors for feedback and improvements

📞 Support


Made with ❤️ by Mohamed Abdo phone

MacOS

phone

所屬分類

原始碼儲存庫

使用此套件的專案