The solution

Add transform parameters

startTrackingPointer(event.pointer,event.transform);

History records

First, demand arises

Customize a control that slides up, down, left, and right on a slideable page.

Second, demand realization

1. Initial implementation

1. Use CustomPaint to paint the control. 2. Wrap a GestureDetector around it and pass in onPanDown, onPanUpdate, and onPanEnd methods respectively to change the property value according to the callback.

2. Problems arise

Found a problem with the gesture effect, when manipulating the custom control, the custom control is not responding, but the sliding parent control is responding. I guess the gesture has a priority problem, because I don’t use the onPan* method and use onVertical*+onHorizontal*+onTapDown to achieve the requirements, but I don’t like the use of this parameter transfer, so I still want to find a solution.

3. Google to find solutions

Finding an article helped me a lot. I knew that I needed to use RawGestureDetector to deal with gestures by myself. It happened that there was a complete code in RawGestureDetector, so I used it directly. There are two main overrides:

1.addAllowedPointer()

2. HandleEvent () code is as follows:

@override void addAllowedPointer(PointerDownEvent event) { startTrackingPointer(event.pointer); if (onPanDown(event)) { resolve(GestureDisposition.accepted); } else { stopTrackingPointer(event.pointer); } } @override void handleEvent(PointerEvent event) { if (event is PointerMoveEvent) { onPanUpdate(event); } else if (event is PointerUpEvent || event is PointerCancelEvent) { onPanEnd(event); stopTrackingPointer(event.pointer); }}Copy the code

The blogger overwrites addPointer and handleEvent, so I changed addPointer to addAllowedPointer, which is actually the best way to do it.

With a little understand gestures is very helpful to me: in the main method to increase debugPrintGestureArenaDiagnostics = true; When there is a gesture, the console will print all the current competing gestures and the winning gesture. Using the blogger’s code, I found that all gestures on my custom control were captured by my control, but at the same time a new problem appeared.

4. LocalPosition value is not correct

When using localPosition, it was found to be correct in onPanDown, but in onPanUpdate and onPanEnd it had the same value as position. So I went to the source code and foundWhen localPosition is empty, the value of position is assigned to localPosition.

5. Find solutions in the source code

I custom GestureRecognizer inherited from OneSequenceGestureRecognizer, so I’d like to see the system can realize OneSequenceGestureRecognizer is how to deal with gestures.

Find a lot of, see HorizontalDragGestureRecognizer it for you.

  • The first step is to look at the addAllowedPointer method. Didn’t see anything useful
  • Step two, look at the handleEvent method. What do you see
  • The third step
    • I suspect there is a bug in Google (because I found a bug before and raised an issue on GitHub, but it hasn’t been solved yet)
    • Reflect on their own look not carefully, just look at a brief
  • Step 4, look again, starting with the addAllowedPointer method

This time, I found that a transform parameter was missing in the red box. After adding it, I tested it and the problem was solved.

“The END”