Hello, in this video, I am going to show you how to return data back from a screen. So we showed you how to send data. As we did here, we send this string x and many variables you want, you're basically invoking the constructor. And depending on which button you click, you either, say Batman in the total or Superman watch, you want to send data back from the screen. Now we can do that as well. So to do that, in the main.in, the main dot Actually, let's handle second page first.
So to actually do it, all you have to do is put comma, and then send the data back, that's literally all you have to do. Just send one piece of data, it could be an array or from an all or nothing list, for example, and you could pass that in the first page. multiple pieces are gonna send a welcome back. That's all I'm gonna say. Then obviously, this could be based on other conditions as well as totally up to you in here at the moment This won't do anything so what we need to do that Pull up strings. First of all, we need to create a global key.
This will be a key for our scaffold. We'll use that to display a snack bar. that's optional for this video simply because if you don't want a snack bar, you could just store in a variable printed out into the console. boffins looks quite good. scaffold state equals new. We don't need new global key global key default state.
Yep, that's it forgot the bracket on there. So we need to apply this to the key to scaffold. So this book key This is basically a lie to it later on and refer to it in a way that Oh, Snap. So now, we need to do is, well we actually no click this right here, we are going to create a separate method, an abstract class on say, go to page and in here we're gonna have a build contract asynchronous. And inside of here we're gonna find out which is basically what that you know value is going to be assigned to that being the term weight navigator. So this part of the code is basically the same context, material, page route concept here.
All right, Tim Cook's second page or wherever Your page is actually called. And I need to add this as well. So I'm just going to do the Batman one for now. And we're going to do, we don't need a semicolon here. Okay, so what I want you to do, because I'm only going to do it for this one, essentially this implementation, only to do it so you can pass in, essentially a variable into this method, and then that gets passed. Next, we are going to say, the fold.
And here is basically where we will launch the snack bar. So we're going to say underscore scaffold, dot current state DOT show snack bar. And here is where we basically need to show our, you know, pretty darn awesome snack bar. So we just do snack bars. We're going to create a new one in here. We need the context for this And to actually get this inside of here, we just put quotation, then we put a semicolon.
And that's it. Okay, so now what we need to do go down here, we can get rid of all this navigator dot push, all we want to do is go to settings, second page, passing the context. Assume that we're all done. Now, let's save it. Make sure you save. Now, if I click Batman, please go back.
Welcome back. There we go. And that's it. Whereas if I was to click Superman, and go back, isn't it because sigma n sigma button has a direct navigator push, it doesn't invoke the go to second page method. So that's one way to do is make this the same as this, but both of these need to pass in a variable. So you need an extra variable here, which is what is passed through so that way you can actually pass data in still But that's how you pass data back.
If you don't want to do a snack bar, you can essentially replace this with assigning the value you got from here to a normal variable in the class that you can access anywhere else. simple stuff really. If you have any questions, feel free to call me a message. And as usual, I look forward to see you in the next video.