digital_signature_flutter 0.0.3 copy "digital_signature_flutter: ^0.0.3" to clipboard
digital_signature_flutter: ^0.0.3 copied to clipboard

This library is used to capture a signature through drawing gestures.The widget also allows you to save a signature as an image.

example/lib/main.dart

import 'package:digital_signature_flutter/digital_signature_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Flutter Digital Signature',
      home: DigitalSignature(),
    );
  }
}



class DigitalSignature extends StatefulWidget {
  const DigitalSignature({Key? key}) : super(key: key);

  @override
  State<DigitalSignature> createState() => _DigitalSignatureState();
}

class _DigitalSignatureState extends State<DigitalSignature> {
  SignatureController? controller;
  Uint8List? signature;
  @override
  void initState() {
    controller =
        SignatureController(penStrokeWidth: 2, penColor: Colors.black);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Digital Signature'),
      ),
      body: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const SizedBox(height: 15),
            const Text('Please put the signature here',
                style: TextStyle(fontSize: 20, color: Colors.black)),
            const SizedBox(height: 15),
            Card(
              child: Center(
                child: Signature(
                  height: 200,
                  width: 350,
                  controller: controller!,
                  backgroundColor: Colors.white,
                ),
                // ),
              ),
            ),
            buttonWidgets(context)!,
            const SizedBox(height: 30),
            // const Text(viewSignature),
            signature != null
                ? Column(
              children: [
                Center(child: Image.memory(signature!)),
                const SizedBox(height: 10),
                MaterialButton(
                  color: Colors.green,
                  onPressed: (){},
                  child: const Text("Submit", style: TextStyle(fontSize: 12, ),),
                )
              ],
            ) : Container(),
            const SizedBox(height: 30),
          ],
        ),
      ),
    );
  }

  buttonWidgets(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        TextButton(
          onPressed: () async {
            if (controller!.isNotEmpty) {
              final sign = await exportSignature();
              setState(() {
                signature = sign;
              });
            } else {
              //showMessage
              // Please put your signature;
            }
          },
          child: const Text("Preview",
              style: TextStyle(fontSize: 20, color: Colors.green)),
        ),
        TextButton(
          onPressed: () {
            controller?.clear();
            setState(() {
              signature = null;
            });
          },
          child: const Text("Cancel",
              style: TextStyle(fontSize: 20, color: Colors.red)),
        ),
      ],
    );
  }

  Future<Uint8List?> exportSignature() async {
    final exportController = SignatureController(
      penStrokeWidth: 2,
      exportBackgroundColor: Colors.white,
      penColor: Colors.black,
      points: controller!.points,
    );

    final signature = exportController.toPngBytes();

    //clean up the memory
    exportController.dispose();

    return signature;
  }

  @override
  void dispose() {
    controller!.dispose();
    super.dispose();
  }
}
8
likes
140
pub points
77%
popularity

Publisher

unverified uploader

This library is used to capture a signature through drawing gestures.The widget also allows you to save a signature as an image.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_svg, image

More

Packages that depend on digital_signature_flutter