4Q-s-r-o / signature

Flutter plugin that creates a canvas for writing down a signature
MIT License
252 stars 83 forks source link

Signing quickly leaves gaps in-between points #11

Closed Kinnear closed 4 years ago

Kinnear commented 5 years ago

Signing quickly on iOS or android makes the signature have gaps in-between points. Any idea what may be causing this?

rknell commented 5 years ago

I have only experienced this on iOS (or its far worse on iOS) if that helps

PeterZainzinger commented 4 years ago

The problem there is the _isFar check has a hardcoded limit of 30. This may also explain why it's happening rather on iOS if the device has on higher resolution.

TBH I don't understand why this check is needed in the first place, maybe someone can explain.

thherman commented 4 years ago

Indeed, the problem is the _isFar check method. The goal of this method is to avoid that, if the user gets out of the boundaries of the canvas then goes back in, the leaving and coming back points get joined by a straight line (see image below).

signature_flutter

However, this is indeed a problem as it prevents the user to sign quickly. Maybe the limit should be an optional argument so we can customize it for our needs.

danielkono commented 4 years ago

Faced the same issue. To solve this problem, i added a new variable which tells me when the input is outside my drawing field or not. So if the input coming from outside into my drawing field the next Point I add to '_points' is a PointType.tap. This prevents the paint method from drawing lines between the last point before input going outside the method and the first point coming from outside into the drawing field.

The solution looks like :

bool isOutsideDrawField = false;
  void _addPoint(PointerEvent event, PointType type) {
    if (_painterKey.currentContext != null) {
      RenderBox box = _painterKey.currentContext.findRenderObject();
      Offset o = box.globalToLocal(event.position);
      //SAVE POINT ONLY IF IT IS IN THE SPECIFIED BOUNDARIES
      if ((widget.width == null || o.dx > 0 && o.dx < widget.width) &&
          (widget.height == null || o.dy > 0 && o.dy < widget.height)) {
        setState(() {
          if (isOutsideDrawField) {
            type = PointType.tap;
          }
          _points.add(Point(o, type));
          isOutsideDrawField = false;
        });
      } else {
        if (!isOutsideDrawField) {
            isOutsideDrawField = true;
        }
      }
    }
  }
parcool commented 4 years ago

1596099926388 There is gap yet. why?

MartinHlavna commented 4 years ago

Is this on mobile or web? Note that original issue was little different it produced gaps that was single not interconnected points. This looks more like rendering issue.

deepak786 commented 3 years ago

@MartinHlavna We also have a similar issue https://github.com/4Q-s-r-o/signature/issues/11#issuecomment-666246471 Tested it on Mobile.