(CRUD)📱Create & Store User Data • Firebase x Flutter Tutorial ♡

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
yo what up welcome back to another quick flutter tutorial in the last few videos we used firebase to create this nice looking login screen and essentially we dealt with the authentication right so we can assign users in we can sign up users and also last video we dealt with this forgot password so we can send them a password link now let's turn our attention to when we go to this register page right now we're just collecting the email and some passwords so let's try to collect some more information about the user okay maybe things like the first name last name and maybe the age and i think that should give you guys enough understanding to add whatever you want for your apps right whether that's price or location things like that so let's give this a go so if you go to your firebase console and you click on the database firestore let's create a database and let's just do test mode for now and let's just choose your location okay i'm just going to use us central so this is where we are going to collect the information from our users and so we can start a collection and i'm just going to call it users and let's just order generate an id just as an example if i was to manually input this let's say the first name is a string and we want to put in mitch so now that we've created a database for it let's go back to our code and the first thing you're going to need to do is to go to your pubspec.yaml and last time we used this firebase auth package for the authentication but now i want you to add this cloud firestore okay and this is the version number that i'm going to use today so save it and what i want to do is we had our login page and if the user registers a new user i want to add some more text fields and let's add a few more details about the user so the age first name and last name and like i said from that you can actually add whatever you want that's more specific to your needs whether that's price or you know where you live and things like that okay so let's go to our register page which is this one here and currently we have three text controllers so the email password and the confirm password so i'm going to create a few more here let's say first name controller last name controller and let's do one more let's do age controller so from here you can add as many controllers as you want so if you want to add some more details like the price maybe the location of where they live i'm just going to do these three and it should give you guys a good idea on how to add more specific to your app so first name last name and age controller so let's just quickly add that here as well cool and let's create the ui for it so i'm just going to grab this first email text field with the size box underneath so that guy i'm just going to create and copy up here and let's make it a first name text field then we should change the controller to the first name controller and the hint text first name okay so we're going to do the same thing and add a couple more so last name text field and finally the age text field so let's have a look at how this looks cool so here it is now it looks like because we have so many text fields up here we can actually clean up some of these so at the top we've got the logo you can leave the logo there if you like but i think i think we're good to just get rid of it that's good enough and so now we can start typing stuff in here right so let's see how to do that in our code so once we fill out all this information and we click sign up we're going to call this signup method and so what it's doing right now is just authenticating the user okay so we're just creating the user right what i'm going to do also is if the password is confirmed and everything's all good then let's add user details okay so i'm actually going to rewrite this and say create user okay so this just creates the user with the email and the password for authentication purposes and then let's add user details after that so for this i'm going to create a new method underneath and say future add user details so if i just show you say um a weight firebase firestore instance this is going to automatically bring in that firestore package that we that we added in earlier so firebase firestore collection and the collection path so this is the name of the collection and we called it users if you don't manually create this like we did at the start of the video then it'll automatically create it so nothing to worry about there and then we can simply just add some information so await firebase firestore the instance and this is the collection that we're going to add it into and let's add it here so this one is going to be the formatting is like a map which basically if i show you we want to add a first name and a last name and also the age email let's say we want to add these for information to our user in our collection so you can actually put in a string here like steve but when we create the user so if i click on register now and the user types in their name steve then we can access this through our first name controller so we want to pass this information through to this method so like let's accept some parameters so in the add user details i want to accept a string called first name a string called last name a string called email and an integer for the age okay so let's just swap these around and we can give the first name here the last name to this one email here and the age can go there cool so now that we created this method when we sign up and we create the user we can now call this method here and say we have to give it the first name so let's say first name controller text and trim it the next thing we need is the last name so i'm just going to copy this but just say last name and we also need the email so let's say email and the last thing is the age controller oops we should get rid of these names now with the age controller because this is an integer like i want it to be an integer whereas the other ones are strings so that's why we have no problem in the first three but this last one is going to give me a text so i want to convert this to an integer so let's just say integer pass this guy cool now let's see if this works i'm just going to save this let's register and let's say steve jobs his age like 77 stevejobs gmail.com and create a password and if i sign up i'm signed in and then if i look at my database here you can see that was the one that we created manually but this is the one that we just created okay so using this we can now have a collection of information that's more than just authenticating the user okay we have information like age first name last name and the email and depending on your specific needs for your app you might need different things right like maybe like the price or something like that maybe the rating as well so a lot of things you can collect about the user but hopefully just with this example you're able to understand how we can add information to our cloud firestore awesome so this bit of code was what we worked on today maybe in the next one we can also work on an ability to have like a settings page that we can update this information through the app okay and we can read and write as well and update and delete so the normal operations will try to cover in the next couple of videos hopefully that was helpful let me know if you have any issues let me know if you have any questions but other than that thanks for watching and i'll catch you guys in the next one peace [Music]
Info
Channel: Mitch Koko
Views: 39,880
Rating: undefined out of 5
Keywords:
Id: idJDAdn_jKk
Channel Id: undefined
Length: 11min 10sec (670 seconds)
Published: Mon May 02 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.