I have this code and I don't know how can I save the signature image it in the device any one know how can I do it? Then I need to retrive this picture again

import 'dart:convert';
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter_signature_pad/flutter_signature_pad.dart';

void main() {

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      home: MyHomePage(title: 'Flutter Demo Home Page'),

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  _MyHomePageState createState() => _MyHomePageState();

class _MyHomePageState extends State<MyHomePage> {
  ByteData _img = ByteData(0);

  Widget build(BuildContext context) {
    var sign = Signature(
      color: Colors.red,
      strokeWidth: 5.0,
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              Expanded(child: sign),
                  maxHeight: 200.0,
                  child: Image.memory(_img.buffer.asUint8List())),
                padding: EdgeInsets.all(25.0),
                Row(mainAxisAlignment: MainAxisAlignment.center, children: [
                      color: Colors.green,
                      onPressed: () async {
                        //retrieve image data, do whatever you want with it (send to server, save locally...)
                        var data = await sign
                            .toByteData(format: ui.ImageByteFormat.png);
                        setState(() {
                          _img = data;
                        debugPrint("onPressed " +
                      child: Text("Save")),
                      color: Colors.grey,
                      onPressed: () {
                      child: Text("Clear")),
        ) // This trailing comma makes auto-formatting nicer for build methods.

Solution 1: boformer

The Signature widget in the flutter example simply paints a path on a canvas:

  void paint(Canvas canvas, Size size) {
    var paint = Paint()
      ..color = Colors.black
      ..strokeCap = StrokeCap.round
      ..strokeWidth = 5.0;
    for (int i = 0; i < points.length - 1; i++) {
      if (points[i] != null && points[i + 1] != null)
        canvas.drawLine(points[i], points[i + 1], paint);

You need to find a way to

  • create your own canvas
  • draw the path on the canvas
  • render the canvas
  • export the rendering as png

Here are the concrete steps:

  • Create a ui.PictureRecorder.
  • Create a Canvasusing the recorder and a Size.
  • Now draw the path on the canvas.
  • End the recording with recorder.endRecording()
  • Get the ui.Image object with picture.toImage
  • Get the image bytes in png format with image.toByteData(format: ui.ImageByteFormat.png)
  • Save it to a file, stream it to a server...

The steps are described in my answer here (although the use case is different): Flutter how to save(re-encode) text overlay on video

Solution 2: Aravind Vemula

pngBytes = image.toByteData(format: ui.ImageByteFormat.png)

now, you have to convert pngBytes to List<int> bytes.

then using File('$path/filename.png').writeAsBytesSync(pngBytes.buffer.asInt8List()) will save your canvas as png on storage

Here is an example

var pngBytes = await image.toByteData(format: ui.ImageByteFormat.png);
// requesting external storage permission
if(!(await checkPermission())) await requestPermission();

// Use plugin [path_provider] to export image to storage
Directory directory = await getExternalStorageDirectory();
String path = directory.path;

// create directory on external storage
await Directory('$path/$directoryName').create(recursive: true);

// write to storage as a filename.png

for complete example visit https://github.com/vemarav/signature