Hello, in this video, I am going to show you how to implement a time picker time picker. Simply put once trigger allows you to select a time. So this is great for me being an alarm reminder system, you know, a bunch of other scenarios as well on the other use cases come to mind, but I'm sure they do for you. If you want to know how to implement a date pickup, feel free to check the previous video for that. So outside of our scaffold our widget he has done for the class, we need to implement a couple of things. So we need to implement need to implement a time so we're going to say fine.
So with the time this will allow us to keep track of it, time of day, time of day. And this is gonna say equals So this is gonna be default on the set and I'm Do time of day dotnet you can overwrite or if you want to, but I'm going to keep it simple and just, you know, put the time that it is currently set to nav, whatever that time will be when we run it. Next, we need to have enough time all day. Know what time of day, actually now, we can use just this one today, we can just use the one. And what we want to do now is create a future a future note, and it's going to be a method that's going to be called once we trigger a wire an event is triggered, or maybe a button for example, I'm going to be implementing the button shortly.
And with the build context, on text. Inside of here, we are gonna say on photon equals show time. that's built in. Now on to the second Semi Pro lawn, and we are going to say the context is equal to the context that's being passed in. Next the other thing is the initial time, this is going to be set to the time so what is going on here? Okay, have a look underscore time equal await show time picker content.
Let me know. Thank you Call it picked and picked pennies on expected for you to have a wait. So let me make sure the future no build context needs to be asynchronous to learn about the async keyword so we can get rid of that we can train it back to on score time when we were kids make sure you don't make that mistake. And now we're going to say if pick is equal to null. So basically, long isn't equal to the current time, then we're going to trigger this event. Then I'm going to say set state.
So the set state is going to say point nine now equal to is now equal to actually now actually should be fine. Let's save that. Let me get rid of this. Let me save this and we are going to need a button. So we're going to need a button. So I'm gonna need a child icon but and for the child in you know we need an icon in here isn't going to be icon, icon long you can have any sort of icon or any sort of button.
They compress the ones that trigger this event my event select And this little context. Now I want to say after this, right? So if we was to refresh that, or we load it reload love the hot reload feature. I clicked that. So maybe, yeah, let's go to our click OK. As you see, there's a problem is this gets triggered straight away. So we don't want that.
And the way we can get around that is by not only here, by having time picked, I'm gonna say is equal to this. Then we're going to say sets date and time equals k. And then if it was between underscore time hot reload it now, as you can see doesn't print anything out. Yeah, let me go to this time. Okay, only Natalie get that and if I go back to it, I didn't see the status been maintained because we are storing it right here. And in terms of the one we would use, we would use this underscore time if we wanted to use it, you know, somewhere else. Maybe this is you know, minder, you click Save reminder, then he will use this to save the time.
That's it for the set time picker. If you have any questions, feel free to shoot me a message. And as usual, I look forward to seeing you on the next video.