signature_pad 2.1.0+1

  • README.md
  • Example
  • Installing
  • Versions
  • 76

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

example/main.dart

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));
  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);

  document.body.append(a);
  a.click();

  Url.revokeObjectUrl(url);
}

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:


dependencies:
  signature_pad: ^2.1.0+1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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';
  
Version Uploaded Documentation Archive
2.1.0+1 Aug 21, 2018 Go to the documentation of signature_pad 2.1.0+1 Download signature_pad 2.1.0+1 archive
2.1.0 Aug 21, 2018 Go to the documentation of signature_pad 2.1.0 Download signature_pad 2.1.0 archive
2.0.0+1 Aug 7, 2018 Go to the documentation of signature_pad 2.0.0+1 Download signature_pad 2.0.0+1 archive
2.0.0 Jul 5, 2018 Go to the documentation of signature_pad 2.0.0 Download signature_pad 2.0.0 archive
1.0.1 May 5, 2017 Go to the documentation of signature_pad 1.0.1 Download signature_pad 1.0.1 archive
1.0.0 May 5, 2017 Go to the documentation of signature_pad 1.0.0 Download signature_pad 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
75
Health:
Code health derived from static analysis. [more]
90
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
60
Overall:
Weighted score of the above. [more]
76
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:signature_pad/signature_pad.dart.

Health issues and suggestions

Document public APIs (-9.85 points)

67 out of 68 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

Maintenance issues and suggestions

Maintain CHANGELOG.md. (-20 points)

Changelog entries help clients to follow the progress in your code.

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

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