6 minutes
Share the link to this page
Pointers represent raw data about the user’s interaction with the device’s screen. There are four types of pointer events: PointerDownEvent The pointer has contacted the screen at a particular location. PointerMoveEvent The pointer has moved from one location on the screen to another. PointerUpEvent The pointer has stopped contacting the screen. PointerCancelEvent Input from this pointer is no longer directed towards this app.


Hello, in this video we are going to look at gestures and more specifically, pointer. So this is really cool. It allows us to create interaction with with our widget could be, you know, we have text on there and image on their button there, you know, conventionally a button immediately, you know, we're about to look like there's a, you know, Jones standard, and you know, you go to click it and there probably be some text in it so you know what it does. But you can attach a, what's called a lift nap to any widget. So you can detect when, you know, the pointer has essentially, you know, clicked any widget. So that's really, really cool.

So we're going to do women a mix, I've got an image right here. And the way to do is really simple. So you need to have your child wherever it is, it could be text, it could be me don't really matter. And you need to enclose it into something else like you know, we've got this container. So we need to have a Something called child listening. In, they will put this, this will be a child of that.

Now to detect, when I'll show you. Before I say this, I'll start clicking on it, nothing is happening cuz we haven't attached any listeners, there's four types of events that you can actually pick up using the point of using pointers is pointed down. event, point to Matt move event, pointer up event and pointed, canceled event. pointed down event. This is when the pointer has contacted screen pointed, meaning you know, your finger or in this case is going to be my math, which is simulating a finger at a particular location. So it's like a click, push while your fingers still on the first time it goes on to it.

Point to move is well, the you know, the pointer is still on the screen. But you're moving it's all like moving the mouse or having the you know, the mouse button that points up is when You stop touching the screen. So you lifted your finger off point to cancel. And this is input from this point is no longer basically directed towards the app. What that means is if something over roids, you know, your phone, like if you have an incoming call, and you're on an application, the application basically goes into the background, and the call comes to the foreground. And if you accept it, you can, you know, start talking to whoever's calling you, if you reject it, you go back to the app.

So that's where the, the cancel event will occur. That's less likely but still useful to handle that and you only need one listener per widget to handle all four of these. So to do it, all you do is see here all the events and you know how to go like how we got the suggestions if you press Ctrl and then state and get the suggestion will first turn it on pointed them in here. You have brackets pointing to down event Call this event, the event that actually occurred. And we can obviously call a separate method bunker, put it in line here, and I'm simply gonna click example. And if I was to say that I click it, as you can see it picks up the click on it, I can click it again and I can click it again.

But let me show you what happens. If I want to wipe the console. Watch what happens. I click it there before I click outside of it, not doing anything, because we've only attached it to this widget. And what we can also do is print out the event. We can get some more extra you know information about you can do this with all the events.

So click that as you can see so far Clicking here by clicking there, we're basically getting pixel coordinates relative to the entire screen. So this is fantastic. And you can use those properties as well. So you can just do event dot, you know, get the Delta you can get, you know, the button has been clicked, there's a whole heap of information and as an extra tap on what you to, you know, experiment with that. So the other one I'm gonna show you is on point to move and you put a pointer, move event and then before the event. We are getting an error.

We'll need a comment here. Too many positional arguments zero expected but one fan well The comment here should not be a comma that isn't there. Before the print anonymous a new form also gonna print out the event. pretty useful on this. The first type that go into it, fight Click, click it, my mass is down. Now if I'm moving on my math is still down and the way you're picking all those movements, and you can see the chord and so this is great for checking the direction you could be using this for swipe.

You could be using me for a whole heap of stuff and let go of it. Letting Go get would trigger the point pointer up event. As an extra task. I want you to implement the pointer or prevent the pointer cantle event pointer up event is easy to essentially trigger just when you lift your finger or your mouse off that particular you know off the screen, but only one CPU can simulate the cancel event. And that's it. If you have any questions, feel free to pop me a message.

And as usual, I look forward to seeing you in the next video.

Sign Up


Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.