dynamic_signature_pad 0.0.1
dynamic_signature_pad: ^0.0.1 copied to clipboard
Capture handwritten signatures as dynamic time-series data (vector strokes with velocity and optional pressure). Lossless JSON/SVG export and PNG rendering. Pure Dart/Flutter, no native code, no third [...]
import 'dart:typed_data';
import 'package:dynamic_signature_pad/dynamic_signature_pad.dart';
import 'package:flutter/material.dart';
void main() => runApp(const ExampleApp());
/// Demo application for `dynamic_signature_pad`.
class ExampleApp extends StatelessWidget {
/// Creates the demo app.
const ExampleApp({super.key});
@override
Widget build(BuildContext context) => const MaterialApp(
title: 'dynamic_signature_pad',
home: HomePage(),
);
}
/// Home page: opens the full-screen, landscape-locked capture screen and shows
/// the result.
class HomePage extends StatefulWidget {
/// Creates the home page.
const HomePage({super.key});
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
Uint8List? _png;
String _info = '';
Future<void> _capture() async {
final SignatureResult? result =
await showDynamicSignature(context, title: 'Sign here');
if (!mounted) return;
if (result == null) {
setState(() => _info = 'Cancelled');
return;
}
setState(() {
_png = result.pngBytes;
_info = 'points: ${result.signature.pointCount} · '
'json: ${result.strokeJson.length} B · svg: ${result.svg.length} B';
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Dynamic Signature Pad')),
body: Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton.icon(
onPressed: _capture,
icon: const Icon(Icons.edit),
label: const Text('Capture signature'),
),
const SizedBox(height: 16),
Text(_info, textAlign: TextAlign.center),
if (_png != null) ...<Widget>[
const SizedBox(height: 16),
DecoratedBox(
decoration:
BoxDecoration(border: Border.all(color: Colors.grey)),
child: Image.memory(_png!, height: 120, fit: BoxFit.contain),
),
],
],
),
),
),
);
}
}