signature_pad 2.1.0+1

Signature Pad Logo

A Pure Dart implementation of Signature Pad by Szymon Nowak. Supports Flutter and browsers.

Signature Pad Demo Signature Pad Demo IOS

Example #

see the example/ directory for a complete example. (e.g. webdev serve example)

Demo #

The example/ directory contains a Dart version of the JS demo


import 'dart:html';
import 'dart:math';
import 'dart:typed_data';

import 'package:signature_pad/signature_pad.dart';
import 'package:signature_pad/signature_pad_html.dart';

void main() {
  var clearButton = querySelector("[data-action=clear]");
  var savePngButton = querySelector("#save-png-button");
  var saveSvgButton = querySelector("#save-svg-button");
  var canvas = querySelector("canvas");
  var opts = new SignaturePadOptions(minWidth: 1.5, maxWidth: 4.0);
  var signaturePad = new SignaturePadHtml(canvas, opts);
  clearButton.onClick.listen((e) => signaturePad.clear());

  savePngButton.onClick.listen((e) {
    download(signaturePad.toDataUrl(), "signature.png");
  saveSvgButton.onClick.listen((e) {
    download(signaturePad.toDataUrl('image/svg+xml'), "signature.svg");

  window.onResize.listen((e) => resizeCanvas(canvas));

void download(String dataUrl, String filename) {
  var blob = dataUrlToBlob(dataUrl);
  var url = Url.createObjectUrl(blob);

  var a = document.createElement("a");
  a.setAttribute("style", "display: none");
  a.setAttribute("href", url);
  a.setAttribute("download", filename);



Blob dataUrlToBlob(String dataUri) {
  const String base64Marker = ';base64,';
  var parts = dataUri.split(base64Marker);
  var contentType = parts[0].split(":")[1];
  var raw = window.atob(parts[1]);
  var rawLength = raw.length;
  var list = Uint8List(rawLength);
  for (var i = 0; i < rawLength; i++) {
    list[i] = raw.codeUnitAt(i);
  return new Blob([list], contentType);

// Adjust canvas coordinate space taking into account pixel ratio,
// to make it look crisp on mobile devices.
// This also causes canvas to be cleared.
void resizeCanvas(CanvasElement canvas) {
  // When zoomed out to less than 100%, for some very strange reason,
  // some browsers report devicePixelRatio as less than 1
  // and only part of the canvas is cleared then.
  var ratio = max(window.devicePixelRatio ?? 1.0, 1);
  canvas.width = canvas.offsetWidth * ratio;
  canvas.height = canvas.offsetHeight * ratio;
  (canvas.getContext("2d") as CanvasRenderingContext2D).scale(ratio, ratio);

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  signature_pad: ^2.1.0+1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:signature_pad/signature_pad.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 2, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.9+1

Health issues and suggestions

Document public APIs. (-0.59 points)

72 out of 73 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/signature_pad.dart. (-4.89 points)

Analysis of lib/signature_pad.dart reported 10 hints, including:

line 42 col 36: Unnecessary new keyword.

line 96 col 19: Unnecessary new keyword.

line 102 col 14: Unnecessary new keyword.

line 130 col 14: Unnecessary new keyword.

line 131 col 14: Unnecessary new keyword.

Fix lib/signature_pad_html.dart. (-2.48 points)

Analysis of lib/signature_pad_html.dart reported 5 hints:

line 47 col 22: 'throttle' is deprecated and shouldn't be used. Use the extension instead.

line 60 col 22: 'throttle' is deprecated and shouldn't be used. Use the extension instead.

line 109 col 12: Unnecessary new keyword.

line 109 col 58: Unnecessary new keyword.

line 145 col 10: Unnecessary new keyword.

Maintenance issues and suggestions

Provide a file named (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (stream_transform).

Package is getting outdated. (-86.30 points)

The package was last published 97 weeks ago.

The package description is too short. (-15 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
stream_transform ^0.0.9 0.0.20 1.2.0
Dev dependencies
build_runner any
build_web_compilers any