签名包是一个 Flutter 插件,提供高性能画布以捕获数字签名。它支持自定义样式、边界约束和初始状态配置,非常适合用于表单和身份验证工作流。该插件专为跨平台使用而设计,在 Android、iOS、Web、macOS、Windows 和 Linux 上均可无缝运行。该插件确保绘制过程流畅且延迟极低,并通过可配置选项提供外观和行为上的灵活性。
适合场景
数字签名收集
带签名验证的表单提交
身份验证工作流
电子签名集成
用户身份验证
主要特点
可自定义的描边样式和颜色
签名区域的边界限制
初始状态支持(例如,预填充的签名)
高性能渲染
跨平台兼容性
可配置的画布大小和内边距
适合对象
需要电子签名功能的应用开发者
需要用户身份验证的表单
具有绘图需求的移动和Web应用
具有合规性要求的企业应用
面向多平台的应用程序
使用建议
需要正确处理画布大小和缩放
可能需要额外的验证来确保签名的真实性
性能取决于设备功能
仅限基本绘图;不适用于复杂绘画
除了图像数据外,没有内置的导出格式
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
signature
A Flutter plugin providing performance optimized signature canvas with ability
to set custom style, boundaries and initial state. This is native flutter
implementation, so it supports all platforms.
Why
In time of creation of this plugin, there was no available solution that had:
required performance on wide range of devices
ability to set canvas boundaries
ability to initialize using previously saved state
Migration to 5.0.0+
This version no longer wraps Signature in Expanded widget if you are using
it without specifying dimensions
This removes error Incorrect use of ParentDataWidget, see
this issue for more
information.
If you are passing dimensions to widget, you do not have to change anything.
If you are using widget without dimensions inside Row, Column or Flex
widgets, you have to wrap Signature inside Expanded yourself.
If you are using widget without dimensions, but not inside mentioned widgets
you do not have change anything and error should dissapear from your logs :)
Take a look at our example project as well: Signature Demo
// IMPORT PACKAGEimport'package:signature/signature.dart';
// Initialise a controller. It will contains signature points, stroke width and pen color.// It will allow you to interact with the widgetfinalSignatureController _controller = SignatureController(
penStrokeWidth: 5,
penColor: Colors.red,
exportBackgroundColor: Colors.blue,
);
// INITIALIZE. RESULT IS A WIDGET, SO IT CAN BE DIRECTLY USED IN BUILD METHOD var _signatureCanvas = Signature(
controller: _controller,
width: 300,
height: 300,
backgroundColor: Colors.lightBlueAccent,
);
// CLEAR CANVAS
_controller.clear();
// EXPORT BYTES AS PNG// The exported image will be limited to the drawn area
_controller.toPngBytes();
// isEmpty/isNotEmpty CAN BE USED TO CHECK IF SIGNATURE HAS BEEN PROVIDED
_controller.isNotEmpty; //true if signature has been provided
_controller.isEmpty; //true if signature has NOT been provided// EXPORT POINTS (2D POINTS ROUGHLY REPRESENTING WHAT IS VISIBLE ON CANVAS)var exportedPoints = _controller.points;
//EXPORTED POINTS CAN BE USED TO INITIALIZE PREVIOUS CONTROLLERfinalSignatureController _controller = SignatureController(points: exportedPoints);
//DONT FORGET TO DISPOSE IT IN THE `dispose()` METHOD OF STATEFUL WIDGETS@overridevoiddispose() {
_controller.dispose();
super.dispose();
}