syncfusion_flutter_signaturepad 19.2.57 syncfusion_flutter_signaturepad: ^19.2.57 copied to clipboard
The Flutter Signature Pad widget allows you to capture smooth and more realistic signatures through drawn gestures and save it as an image.
import 'dart:ui' as ui;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_signaturepad/signaturepad.dart';
void main() {
return runApp(SignaturePadApp());
}
///Renders the SignaturePad widget.
class SignaturePadApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SfSignaturePad Demo',
home: _MyHomePage(),
);
}
}
class _MyHomePage extends StatefulWidget {
_MyHomePage({Key? key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<_MyHomePage> {
final GlobalKey<SfSignaturePadState> signatureGlobalKey = GlobalKey();
@override
void initState() {
super.initState();
}
void _handleClearButtonPressed() {
signatureGlobalKey.currentState!.clear();
}
void _handleSaveButtonPressed() async {
final data =
await signatureGlobalKey.currentState!.toImage(pixelRatio: 3.0);
final bytes = await data.toByteData(format: ui.ImageByteFormat.png);
await Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Container(
color: Colors.grey[300],
child: Image.memory(bytes!.buffer.asUint8List()),
),
),
);
},
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
Padding(
padding: EdgeInsets.all(10),
child: Container(
child: SfSignaturePad(
key: signatureGlobalKey,
backgroundColor: Colors.white,
strokeColor: Colors.black,
minimumStrokeWidth: 1.0,
maximumStrokeWidth: 4.0),
decoration:
BoxDecoration(border: Border.all(color: Colors.grey)))),
SizedBox(height: 10),
Row(children: <Widget>[
TextButton(
child: Text('ToImage'),
onPressed: _handleSaveButtonPressed,
),
TextButton(
child: Text('Clear'),
onPressed: _handleClearButtonPressed,
)
], mainAxisAlignment: MainAxisAlignment.spaceEvenly)
],
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center));
}
}