4Q-s-r-o / signature

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

When use onLongPress method to clear signature pad, it clear signature but when we start draw signature again it will display dot in position where we press long tap #88

Closed beamAkshay closed 1 year ago

beamAkshay commented 1 year ago

https://user-images.githubusercontent.com/100898974/222066040-f6e737c6-ef07-4c35-ae96-bbc557e99cf1.mov

code :

GestureDetector(

          onLongPress: () {
                   setState(() {
               _secondSignatureController?.clear();
                                     });

                                        },
MartinHlavna commented 1 year ago

Unfortunately we can't stop listening for events. You can kinda get away with implementing onLongPressEnd also, but if user starts to draw immediately without lifting finger it would also clear the points. But maybe you can work from there

GestureDetector(
            child: Signature(
              key: const Key('signature'),
              controller: _controller,
              height: 300,
              backgroundColor: Colors.grey[300]!,
            ),
            onLongPress: () {
                setState(() {
                  _controller.clear();
                });
            },
            onLongPressEnd: (details) {
              setState(() {
                _controller.clear();
              });
            },
          ),

If PR #89 gets merged it could also come in handy for you since you can disable canvas in onLongPress and reenable it in onLongPressEnd

MartinHlavna commented 1 year ago

5.4.0 with PR #89 has been published. Now you can do

GestureDetector(
    onLongPress: () {
        setState(() {
            _controller.disabled = true;
            _controller.clear();
        });
    },
    onLongPressUp: (){
        setState(() {
            _controller.disabled = false;
        });
    },
    child: Signature(
        key: const Key('signature'),
        controller: _controller,
        height: 300,
        backgroundColor: Colors.grey[300]!,
    ),
);