Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

create canvas for signature flutter

import 'package:flutter/material.dart';

class SignaturePainter extends CustomPainter {
  SignaturePainter(this.points);

  final List<Offset> points;

  void paint(Canvas canvas, Size size) {
    Paint paint = new 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);
    }
  }

  bool shouldRepaint(SignaturePainter other) => other.points != points;
}

class Signature extends StatefulWidget {
  SignatureState createState() => new SignatureState();
}

class SignatureState extends State<Signature> {
  List<Offset> _points = <Offset>[];

  Widget build(BuildContext context) {
    return new Stack(
      children: [
        GestureDetector(
          onPanUpdate: (DragUpdateDetails details) {
            RenderBox referenceBox = context.findRenderObject();
            Offset localPosition =
                referenceBox.globalToLocal(details.globalPosition);

            setState(() {
              _points = new List.from(_points)..add(localPosition);
            });
          },
          onPanEnd: (DragEndDetails details) => _points.add(null),
        ),
        CustomPaint(painter: SignaturePainter(_points), size: Size.infinite),
      ],
    );
  }
}

class DemoApp extends StatelessWidget {
  Widget build(BuildContext context) => new Scaffold(body: new Signature());
}

void main() => runApp(new MaterialApp(home: new DemoApp()));
Comment

PREVIOUS NEXT
Code Example
Python :: how to add previous and next in tkinter in python 
Python :: how to get a rectangular grid out of two given one-dimensional arrays 
Python :: Subtract layers 
Python :: monthly precipitation in python 
Python :: first_list = [10,20,30,40] second list = first list second list[3]=400 
Python :: numpy get length of list 
Python :: python requests json backslash 
Python :: ValueError: expected sparse matrix with integer values, found float values 
Python :: in python, i am pustin two star before paramerter what is that men 
Python :: django rest framework foreign key relation giving error in serializer 
Python :: can you use the astro a50 with a phone 
Python :: print less than specific number in one row python 
Python :: how to mine bitcoin in python 
Python :: tkinter add new element into grid by click 
Python :: python sha256 crypt decrypt 
Python :: zeromq pub sub example python 
Python :: Return an RDD of grouped items. 
Python :: pyqt5 how to see if clipboard is empty 
Python :: pyfcm image 
Python :: see you tomorrow in italian 
Python :: sns.distplot fit 
Python :: get_absolute_url method on the model 
Python :: dont squeeze plot when creating colorbar matplotlib 
Python :: !python read data from mysql and export to xecel 
Python :: py 
Python :: how to get the number in the tenths place of a integer in python 
Python :: convert to pdf fresh little library that outputs our notebook in a nice LaTex format without installing/doing anything else. 
Python :: break line text opencv 
Python :: rolling window 2d array 
Python :: initial TypedMultipleChoiceField django 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =