Flutterflow - Custom Functions To Simplify Locations (@flutterflow)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so it can be handy to want to send information to create complex information back out of flutter flow to something like you know Zano or another back end but when you do it the complex types like the location type can be pretty bad for that job so let's let's take a look at this let's just say for sake of argument you want to have a new backend followers make a new one for a second here and action and the action will be say an API call to let's just say I had a relatively simple one just called it Bibble right now which just wants a single which wants to take like your latitude longitude but what you'd like to be able to give it would be a from the current location of the user but the problem is red the current device location and the reason for that is that the current device location is not in fact a number it is instead a complex object and what I could do is go over to my API calls over here I could change the Bible and it's not actually going to work setting things to change AI like this so if I have a query parameter I could say that it's going to come from the variable and I can say what my variable is going to be and I can say my variable is just going to be I don't know like a string or something and I'm pretty sure if I were to say it as a string I should let it go through but it will go through in a really useless way it would look like lat long with parentheses and whatever supposed to be inside you wind up doing some text parsing that's not really that useful but just to illustrate the fact that it would probably work I can go back into here to click on open click on here change the value and go to my Global properties I'll give my current device location because we'll do one of the covers is what we call a two string method so any given object in all the complex ones from for mostly's languages you can say I want to take this object turn it into a string and I'll turn something that looks like what we really want so what I could do here is just say it would probably look like lat long and then negative 4.2 comma neg you know three point I mean 38.2 or whatever it is but it would look like something like that which wouldn't actually be helpful to you because what you're looking for in this case just get like latitude and longitude how do we extract simple things from these complex types and the tricky part about that if I just go fix this for a second and go back over to my variables I'm going to tell my variable is not the string it's going to be a double which will then have the effect once I click save here and I go back up to here that the I might open this up and click on this call if I click on latitude won't actually let me use that Latitude anymore because current device location doesn't actually match that type because even though latitude and longituder are both obviously numbers the lat long together is this more complex type so how do you break up these kind of compound types and the answer is going to be like I said through a custom function and I I made one over here that we could take a look at here you have a custom function and if I you know what I'm going to do I'm going to make one for longitude because I already made the one for latitude here so let me just walk you through the process you click on the add button you say I want to make custom function we'll call it get longitude and then it's going to say the return type is actually going to be a double right because we know that longitude is supposed to be a number which is the number of degrees north south supposed to be North is positive South is negative and the and then we can add argument to it and arguments want to take we call it lat long it's going to actually be of type and this is the cool part here an internal one like lat long so you'll notice there are other sort of complex types that are in here like Google place and lat long and range and some of these others and and this approach is a really useful one for being able to extract useful information so now I can say double that long and what I want to do is just help to return and the cool things I do when I'm working in these custom functions or any of the code in fireflow is pause because it has built-in intellisense under the covers it's using uh Visual Studio codes monocle adder and it will it will reveal to you what you can type after that so by just typing in what I knew was the input which was lat long and then just doing a dot it tells me okay these are things I can use and here I want to say I'm going to get longitude and now it's like wait you can't do that why can't I do that I can't do that because of something called an optional key that's up here and we could mess with this more but how about we just not and we just say question mark and that way it will return lat long if it exists and return longitude and I think otherwise it'll return a zero and we'll turn a null if it doesn't actually have a number and it will return a whatever the actual longitude is if it does have the actual longitude I'll call that get long and you can see up here I made another one called uh what we'll call it no save save there we go and I can click on this new custom function I'm just going to rename it getlat which one I previously made you can see it works basically the same way and it doesn't like that at all great okay now it says returns get lat fine save and I can check for errors beta submissive or no errors fantastic so now we can do is now we have this get Latin get long but we can't we have to break up the location into both the latitude and longitude and I can open this guy up and I go back into my back end call which I was calling bill and I can set the variable to not just current device location we don't do it that way we're going to it's going to remove that and we're going to say instead we want to actually work off a function because first you have to say the function then you'll pass the argument the function is going to be the get lat and the latitude is going to come from Global property is current device location see and we can say confirm and now there's another variable that's also going to require which is going to be called we're going to get the longitude and the longitude we're going to say use the function once again so first you pick the function and then you apply the underlying variable to it this caused me a lot of confusion before and I say current diversification and confirm see now what will happen is I will send back to my back end it could be your xano it could be your Firebase it could be whatever you're using for your back end for water flow but you're sending a Latitude you're sending a longitude you're saying them as individual numbers that you're able to extract because you made this relatively simple function which I will put back over here and the and the show right here and the key thing with this there's only one line we ever had to change in here change return value you change the arguments and you insert this one line of code which won this for longitude one which is for latitude and remember the whole idea is we're going from complex to simple and so we're better off having two simple functions rather than one complex one so I hope this is a useful introduction to using custom functions to making the complex things simple in fart flow and I'll see you again soon
Info
Channel: State Change
Views: 3,764
Rating: undefined out of 5
Keywords: Descript
Id: 23NM9JyRjQg
Channel Id: undefined
Length: 7min 6sec (426 seconds)
Published: Sun Aug 27 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.