pskink / matrix_gesture_detector

A gesture detector mapping translation/rotation/scale gestures to a Matrix4 object.
Other
134 stars 101 forks source link

Callback that fires when gesture ends? #5

Closed mblaughton closed 4 years ago

mblaughton commented 4 years ago

Love the library! Clear, concise, efficient, flexible, and great comments!

I have implemented a pinch-to-crop feature and I'm saving the final translation and scale to local storage so images can be displayed later according to a user-specified crop. Right now I'm writing out these values every time onMatrixUpdate() executes, but this understandably causes some lag.

I really only need to write the values when each gesture ends. Is there a convenient way to do this or will I need to expose it by customizing matrix_gesture_detector?

Thanks! Mike

pskink commented 4 years ago

hi Mike

thank you for your nice comments, it would quite easy to add such a feature, if you see https://github.com/pskink/matrix_gesture_detector/blob/master/lib/matrix_gesture_detector.dart#L115 GestureDetector is returned from build method and if you add onScaleEnd: someMethod you will see that someMethod is called when gesture ends - but ... if you use two finger gesture like scaling or rotating it is called twice when you lift up the first and the second finger and i have no idea how to detect the last one, any idea?

mblaughton commented 4 years ago

Excellent. I tried the suggested change and it solves my problem. The few extra calls to GestureDetector.onScaleEnd() won't hurt my app because they are infrequent, but I agree it would be better to filter them out. I can't tell if the spurious events are from a bug in Flutter or just a subtle behavior.

I found this possible workaround for the events but haven't tried it yet: https://github.com/flutter/flutter/issues/13102

At least I suspect this is the same underlying behavior we are seeing. Their solution is to wrap GestureDetector with a Listener and keep a count of fingers touching the screen. That way they can choose to ignore events when only one finger is on the screen.