kayiv_signature_pad 1.0.1
kayiv_signature_pad: ^1.0.1 copied to clipboard
A high-precision signature pad widget for Flutter, offering smooth rendering, pressure sensitivity, undo/redo, and advanced customization with export capabilities.
Kayiv Signature Pad #
A high-precision signature pad widget for Flutter, offering smooth rendering, pressure sensitivity, undo/redo, and advanced customization with export capabilities.
Features #
- β¨ Smooth signature drawing with Cubic BΓ©zier curves
- π± Pressure sensitivity for stylus-supported devices
- π Undo and redo strokes
- π€ Export to PNG or SVG formats
- πΎ Save and load signatures
- π Form field integration
- π¨ Customizable pen types (ballpoint, fountain, brush)
- ποΈ Touch and pressure sensitivity controls
- π― Drawing boundaries and constraints
- βΏ Accessibility support
- π Cross-platform (iOS, Android, web)
Installation #
Add to your pubspec.yaml:
dependencies:
kayiv_signature_pad: ^1.0.0
Run flutter pub get.
Usage #
Create a Controller: #
final controller = SignatureController(
penColor: Colors.blue,
minStrokeWidth: 1.0,
maxStrokeWidth: 5.0,
smoothRatio: 0.65,
penType: PenType.brush,
enableTouchSensitivity: true,
enablePressure: true,
onDrawStart: () => print('Drawing started'),
onDrawEnd: () => print('Drawing ended'),
);
Add SignatureFormField Widget: #
SignatureFormField(
controller: controller,
backgroundColor: Colors.grey[200]!,
width: 300,
height: 200,
validator: (value) => controller.isEmpty ? 'Signature required' : null,
)
Use in a Form: #
Form(
key: _formKey,
child: SignatureFormField(
controller: controller,
validator: (value) => controller.isEmpty ? 'Signature required' : null,
),
)
Control the Signature: #
// Basic controls
controller.clear() // Clear all strokes
controller.undo() // Remove last stroke
controller.redo() // Re-add last undone stroke
// Export options
await controller.toPngBytes() // Export as PNG bytes
await controller.toSvg() // Export as SVG string
// Pen customization
controller.setPenColor(Colors.red) // Change pen color
controller.setPenSize(2.0, 8.0) // Set min/max stroke width
controller.setPenType(PenType.fountain) // Change pen type
controller.setTouchSensitivity(true) // Enable/disable touch sensitivity
controller.setPressure(true) // Enable/disable pressure sensitivity
Example #
Scaffold(
body: Column(
children: [
SignatureFormField(
controller: controller,
validator: (value) => controller.isEmpty ? 'Signature required' : null,
),
Row(
children: [
ElevatedButton(onPressed: controller.undo, child: Text('Undo')),
ElevatedButton(onPressed: controller.redo, child: Text('Redo')),
ElevatedButton(onPressed: controller.clear, child: Text('Clear')),
ElevatedButton(
onPressed: () async {
final bytes = await controller.toPngBytes();
// Handle PNG export
},
child: Text('Export PNG'),
),
],
),
],
),
)
API #
SignatureController #
Properties:
penColor: Pen color (default: Colors.black)minStrokeWidth: Minimum stroke width (default: 1.0)maxStrokeWidth: Maximum stroke width (default: 5.0)smoothRatio: Curve smoothness (0.0-1.0, default: 0.65)penType: Pen style (ballpoint, fountain, brush)enableTouchSensitivity: Enable touch sensitivity (default: true)enablePressure: Enable pressure sensitivity (default: true)onDrawStart: Callback when drawing startsonDrawEnd: Callback when drawing endsisEmpty: Checks if canvas is empty
Methods:
clear(): Clears all strokesundo(): Removes last strokeredo(): Re-adds last undone stroketoPngBytes(): Returns PNG bytestoSvg(): Returns SVG stringsetPenColor(Color color): Change pen colorsetPenSize(double min, double max): Set stroke width rangesetPenType(PenType type): Change pen typesetTouchSensitivity(bool enabled): Enable/disable touch sensitivitysetPressure(bool enabled): Enable/disable pressure sensitivity
SignatureFormField #
Properties:
controller: Required SignatureControllerbackgroundColor: Background color (default: Colors.white)width: Widget width (default: 300)height: Widget height (default: 200)onSaved: Form save callbackvalidator: Form validation callbacksemanticLabel: Accessibility label (default: 'Signature Pad')
License #
MIT License