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

hand_signature 封面
套件詳情v3.1.0+2

hand_signature

允許繪製平滑簽名的簽名墊小部件。提供多種繪製和匯出設定,並支援 SVG。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.2萬
喜歡數
306
Pub 分數
150

安裝套件

flutter pub add hand_signature

套件介紹

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

一個用於建立順暢、互動式簽名板的 Flutter 小部件,支援自訂繪製和匯出選項。支援多個平台,包括行動裝置、網頁和桌面。提供 SVG 匯出和彈性樣式設定,以符合各種應用需求。適用於需要使用者簽名的表單、身分驗證和數位文件。

適用情境

  • 數位表單提交
  • 透過簽名進行使用者驗證
  • 電子簽名收集
  • 文件審批流程
  • 在線合約簽署
  • 行動應用程式註冊

主要特色

  • 平滑簽名繪製
  • SVG 匯出支援
  • 可自訂的描邊寬度與顏色
  • 跨平台相容性
  • 即時渲染
  • 可設定的匯出設定

適合對象

  • 需要電子簽名的應用
  • 表單密集型應用
  • 具備使用者輸入的行動與網頁應用程式
  • 數位文件工作流程
  • 教育或企業軟體

使用建議

  • 需要使用者觸控輸入
  • 效能可能在低階裝置上有所差異
  • SVG 匯出可能需要額外的處理
  • 限制為2D繪圖
  • 無內建儲存或驗證
  • 不適用於高頻率使用情境

原始 README

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

Hand Signature

pub.dev

A Flutter plugin providing a Signature Pad for drawing smooth signatures. This library is written in a pure Dart/Flutter environment to provide support for all platforms. It's easy to use, with a variety of drawing and export settings, and also supports SVG files.

Signature

The signature pad drawing is based on Cubic Bézier curves and offers a choice between performance and 'beauty' modes.


Features

  • Cross-Platform: Works on any platform supported by Flutter.
  • Customizable: Adjust stroke width, color, and smoothing.
  • Multiple Drawing Types: Choose between line, shape, and arc presets for different visual styles. It's also possible to implement a custom drawing experience.
  • Velocity and Pressure Based Stroke: The thickness of the line can vary based on the drawing speed and pressure.
  • Export Options: Export signatures as PNG, SVG, or raw data (JSON/Map).
  • Import/Export: Save and load signature data state.

Usage

Here is a simple example of how to use the signature pad.

import 'package:hand_signature/signature.dart';

final control = HandSignatureControl(
  initialSetup: SignaturePathSetup(
    threshold: 5.0,
    smoothRatio: 0.65,
    velocityRange: 2.0,
    pressureRatio: 0.0,
  ),
);

final widget = HandSignature(
  control: control,
  drawer: ShapeSignatureDrawer(
    color: Colors.blueGrey,
    width: 2.0,
    maxWidth: 10.0,
  ),
);

HandSignatureControl

This class handles the logic behind the signature, controlling input touches and managing the control points of the signature curve. SignaturePathSetup defines how input data will be handled.

  • threshold: Controls the minimal distance between two points. A higher distance creates a smoother, but less precise, curve.
  • smoothRatio: (0 - 1) Controls how smooth the curve will be. A higher ratio creates a smoother, but less precise, curve. The best results are typically between 0.5 and 0.75.
  • velocityRange: Controls the curve size based on the drawing speed. A thin line corresponds to a fast movement, while a thick line corresponds to a slow movement.
  • presureRatio: (0 - 1) Ratio between pressure sensitivity and velocity. 0.0 = only velocity, 1.0 = only pressure. Some platforms/devices (like mouse pointer) doesn't support sensitivity'
  • args: Custom variables - mostly used for custom HandSignatureDrawer.

HandSignature

This widget handles touch gestures and draws the curve on the canvas.

  • control: The HandSignatureControl that processes input and stores the raw data.
  • drawer: The HandSignatureDrawer that handles the painting of the signature.
  • backgroundColor: The background color of the signature canvas.
  • placeholder: A widget to display when the signature is empty.

Drawers

Drawers are responsible for rendering the signature on the canvas. You can use one of the pre-built drawers or create your own.

Pre-built Drawers
  • LineSignatureDrawer: Basic line with a single line width.
  • ShapeSignatureDrawer: Default drawer, mimics an ink pen. It varies line width based on velocity and/or pressure. This is a good option for exporting to SVG.
  • ArcSignatureDrawer: Also mimics an ink pen, but is less performant than ShapeSignatureDrawer. This is the default drawer when exporting to an image.
  • DynamicSignatureDrawer: Dynamically selects the drawing type based on provided arguments.
  • MultiSignatureDrawer: Combines multiple drawers, allowing for complex effects and layering.
Custom Drawer

You can create a custom drawer by extending HandSignatureDrawer and implementing the paint method. This allows full control over how the signature is rendered.

class MyCustomDrawer extends HandSignatureDrawer {
  @override
  void paint(Canvas canvas, Size size, List<CubicPath> paths) {
    // Custom painting logic here
  }
}

Check custom_sample.dart for dynamic setup and drawing. Custom Drawer


Exporting

You can modify properties like canvas size, stroke width, and color during export. You can also provide a custom drawer when exporting to an image. The most common export formats are SVG and PNG. During export, data are re-rendered with the preferred setup and output dimensions.

State can be saved with toMap() and restored with the import() method.

final control = HandSignatureControl();

// Export to SVG
final svg = control.toSvg();

// Export to PNG
final png = await control.toImage(
  width: 512,
  height: 512,
  drawer: ShapeSignatureDrawer(
    color: Colors.black,
  ),
);

// Export to raw data
final data = control.toMap();

// Import from raw data
control.import(data);
  • SVG:
    • shape: Generates a reasonably small file that is well-supported by most programs.
    • arc: Generates a larger SVG file, which some programs may struggle to handle.
    • line: A simple Bezier curve.
  • Image: Export to an Image or Picture object, which can then be converted to PNG bytes.
    • arc: Default drawer when exporting image data.
    • drawer: Specifies HandSignatureDrawer to use during canvas export.
  • JSON/Map: Export the current state as raw data, which can be used later to restore the signature.
    • Data is exported with timestamp and pressure information for each point.
Displaying an exported SVG file

You can display an exported SVG file using a library like flutter_svg.

所屬分類

原始碼儲存庫

使用此套件的專案