Flutter Tutorial - Cloud FirestorešŸ”„ | Flutter Firestore CRUD | Flutter Firestore Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
as what so welcome back to the channel doubling developer and Here I am with yet another exciting episode and this time we'll be learning cloud file store a big hype and fluttered community everyone is going on for this wife why to choose firebase over others and well firebase provides us with two databases one is real time database and other is cloud forest cloud file store by some means is a flagship database offered by firebase so we look into the files to how we can implement our integrate file store in a flutter application and why is it called real time and we'll discuss everything in this video watch the video till end don't skip anything because each and every second counts and I try my best to make it count for you right every minute is a new learning for you so without wasting any time let's begin this tutorial [Music] okay first of all there are some pretty cool sight that you need to do so we'll open our console as you can see go to your firebase console choose your project this was the project that we made if you don't know you can follow our previous videos there we have discussed all about authentication and how to add firebase to your flutter application the correct way yes the procedure to add firebase to application is different for Android and iOS so do follow that video if you are just starting with firebase and what you need to do is go to database and you can see that it will take some time and load so we have two options first one is the cloud Firestone it sees real time updates powerful queries and automatic scaling so to know about all these like what are real time updates powerful queries and automatic scaling you can go to our website so our website is the growing developer dot o-r-g and you can see that I have written a blog just for this which database to use as you can see here that we have a real time option and the cloud files tool so open up this and you can decide which database to choose for editor application both working as kind of similar way both are no sequel database but the key point and key aspects will be discussed in this blog so go ahead and check it and yes we have other blogs as well so we are now concerned about the cloud file store so let's click on create database and it is saying way to start start in production mode or start in test mode so what we'll do I guess I'll start in production mode right now click on next and it is asking for a cloud store location so for India I can like I guess it is Asia South right so done you can choose the location based on your continent and the location like for India is on the southern part of Asia so it will take some seconds and yes your cloud sure your cloud file store will be up in no time and yeah for firebase all the implementation is pretty easy but the pretty cool site configuration for that is very important and that's why I always show the configuration part most of the videos you know just skip the configuration part so here I am nothing being skeptic an see all the configuration done right in front of you so you can see that this is the panel that we will have and this is the rules so the rule says that allow read and write right so it is like everyone can anyone can read or write to what at abased so you can always monitor those tools so the database structure is like we have some collections let's just give it the data collection name as data next then you can always have some document you will check it to document ID and let's just see if this right so after some time you can see that we have some collection and inside the collection I have some document so it is like a table and inside the table you have different rules right similarly I can add any other document and then the document itself can have multiple collections as well so it's totally or says how you want it so right now I'll just delete this so delete document okay so you can see that we don't have any of the documents right now okay I don't want to read the collection right now so okay so there you go see oh so we only have the data collection the name as data and nothing else right now let's move on to our application part so what I have done till now is if you go to my Bob struck 30ml file you can see that I have added cloud files for plugin now this plug-in enables you or contains all the required SDKs now let's move on to our files what I have created you can see that this is our main dog file what the previous video for this UI because I have discussed all about the UI there get started and then we have this UI this is the login screen and inside this login screen you can see that when we click on login we directly add the email and the password to it and then we will move on to a new screen this is new to this video I have created a new drug screen let me show you if we click on login so this is our crud operations now in this screen if I open this now this is a very basic you I have done nothing just added at xcode operations on cloud file store and then I have added some material buttons these are for material bitters that do nothing like now right they are not doing anything and what is this now you can see that I have created a map data right and right now I'm just displaying it by converting into string so this is a text which is displaying this data I have not done anything with this data that's why it is displaying null so whatever I will be doing with the firestore thing it will be shown here and I'll also tell you how to make it real time what else we need right okay so let's first to how to add data we should have some data and then only we can move on to face data update data or delete data whatever date I'll add here will be displayed here fine done okay so let's start with adding the data so for data you have to add the data in the form of map okay so what are we gonna do is in this our data button you can see that this is on pressed I'll just remove this and write add data right this is a method that we still need to make so I'll make that a method here next thing in this a data body what we will write is collection reference I'm directly moving on to collection reference what does this collection reference means this is a reference that I'll use for this collection of this collection which is name of data so anywhere wherever I'll use this collection reference it will refer to this data okay so I'll name it as collection reference equals to fire store dot instant dot instance we'll make an object and dot collection this is the path that is the name of collection for you so this would be data okay so now understand what this line does this collection reference is a reference variable which will refer to this collection data inside our files too right done the next thing that we would do is we will write collection reference dot add right we will add some data now this is asking for some map string dynamic that is it is asking if the data in the form of JSON so what we'll do we'll write map demo data equals to like this right now this type should be string and then a dynamic type right inside this I'll write name name value would be the growing developer right now would be the motor it has let's learn and grow together yeah yeah learn you have seen this many times in my introduction as well so that's all so this is the data that we'll add into our collection so instead of this data I'll write demo data right now what I'm gonna do is I'll be adding this collection reference add demo data now this data will be added to our firebase okay let's see if this works or not so I'll just reload this application once and let's see if we have any exceptions or not okay so cool we got some expect exceptions missing or insufficient permissions that is we don't have any permission to write in the database right so what we'll do is right we will just change it to allow read and write and just publish it your security rules are defined as public so anyone can steal modify delete data in a database don't worry this is just a demo database so nothing is gonna like affect you so this is like allowed written right anyone can read or write in a database done you can always play with these rules in some coming videos I will tell you how to write rules for a database to make it more secure but right now for demonstration purposes I'm keeping it like this okay now let's try this again data and no errors let's check out your guitar so inside our data I have a field and the it says name as the growing developer and MOTU as the let's learn and grow together okay you don't see this right so okay let's do one thing I'll put this emulator here right and then let's see we will see adding data in real time if we click on add data and you can see that this new data is now generated here once again third data so that's how we are creating the data and it is being added in our firebase INR file store let me just remove the extra fields here I delete document here as well delete document and we only have one data now let's try to fetch this data to our application how to write the fetch operation okay so what we'll do is come on simulator yes okay so how to face this data so what we'll do let's create another method name it as fetch data right now this is where we will write we'll change the map beta so this remains the same okay so here is a cool thing in fetch data we'll be adding some listeners to our application don't worry don't be afraid of the terms that I'm using directly right collection reference dot snapshots what does the snapshot means snapshot is whatever data whatever packets of data accessing from the cloud file store so how to declare our listener for it alright listen now what does this mean put a semicolon here that means from the snapshots that I am getting from the collection reference this snapshots is a stream and we have a listener okay so we have introduced two terms here one is stream and one is listener don't worry this channel is all about learning and growing so now we have started with streams and listeners so very soon as we're floating a on streams and listeners that will be especially for them and you can understand how you can manage state using streams and listeners right now you can understand like we have a stream and we are listening to whatever data we are getting that's why it is real-time data so instead of this event I'll write data okay rather I'll just name it a snapshot so whenever there is a change in the database that is whenever any value is added in the database and the value is deleted in the database it listens to it okay that's cool so we'll set state we'll set state data as snapshot dot documents now this document is a list as I told you in our collection we can have multiple documents like you can see like this and like this we have three documents here so this will return document snapshot dot documents will return a list a list of documents right now we only have one document let me just remove this again think of this count remove this as well so right now I only have one document right so this is pretty like straightforward now if you want to get all the documents in the collection you will write like list of documents and you can write it like this documents equals to snapshot or documents right now this will give you the list of documents this can be stored in a list and then from the list you can access everything now if you don't know how to parse the JSON from a list go ahead and check out the video in the info section as well as in the description where I've told you how to parse the data right so right now we don't have anything like documents so it will be document data equals two shot documents and I can put two zero here dot it'll make sense understand this once again what is this data this data is something that I'm gonna print here right now the value is null so when we will call this face data it will fetch the data from the collection reference that is anything that we have in this collection data now inside this data I have a document so I'm using documents of zero that means only the first element in a list now first element dot data whatever data I have in this so it will return a map this will be returned inside a map the same way we added this right so yep let's save this and see if it works or not okay so I'll click on face data once I click on this nothing happens why is this not happening because we have not yet called the face data method okay so here that as the empty function I right fetch data right yeah everyone makes mistakes right so yep fetch data and that's at just look at the speed of fire story with flutter right we have the data as a what you say like mmm JSON format as a map so what I can do is here with this data to string I can write data then we have name let's see if it works so you can see that the growing developer is being displayed and I can write motto and let's learn grow together right okay so now why is this real-time because once you start fetching data once you add some listeners so whenever there is some change in this snapshot whenever that's the main use of listeners whenever there is some change in snapshot it will set state each time there is change you don't agree with me okay let me just show you so once again we will just come here simulator okay so we have the simulator here we have the s-- here let me just minimize this like this okay yet till you load it no worries so you can see that this photo is being displayed here so what I'm gonna do is I'll just write let's learn and grow together fast or in real time right so as soon as they update in this you can see that the update being displayed here so click on update and there you go hey when I start playing with that like it's so cool that everything is in real time if I change it back to together nothing editing going on I updated here and you see the change here that's why it is real time now in normal circumstances where you call the HTTP protocols HTTP GET commands you need to call the command again and again but this listener is doing the work here right so yeah simulator okay so you will just bring it here let's move on to delete data come on how we can delete the data from the database so you can see that we have only one data here so let's delete this as well so we will write a delete data command or method how to do delete it now there is some thing that you need to concentrate as well right this will be an asynchronous command because we don't want to declare any streams for deleting why because for streams if stream listen to any wind we want to fetch the data that is we want to change the date on any event we don't want to change we can say that we don't want anything to happen when we are deleting we can't use snapshots taht listen on the delete data method why because I don't want to delete the data on each event right listeners occurs on each event so what we'll do we'll just copy this once again and we will write query snapshot query snapshot that is we are running some query on the database to get the document so right collection reference dot get document this is a query that we are running and of course this will be a weight not it it will require some time right now next thing is after that will read query snapshot dot documents now this will again have the list of documents we are only concerned with the first document here say well dried 0 dot reference dot delete we'll take the reference and from that reference we will delete the document right now before deleting I would like to add the data so that we have two data and we can read only one of them so next thing is to call this data we would move on to this delete data method here this is empty method and instead of this I'll write delete data to comma save this and you have two documents here and let's see if I delete data there's correlated and we have only one document right so let's add the data again we have one data if I press on delete data you can see in real-time that it is getting deleted okay so we are able to dig the data we are able to face the data and this remains intact based on the document that we have right okay so next thing is to update the data how to update the data so let's write the update data come on update data now this will be same as Tilly data because I don't want to update the data after each event so I'll just copy this paste it here and instead okay we have to declare it a synchronous one and instead of this delete I'll write update data and the updated data should be here so as an updated data I'll write name as sahib singh right and then again see sizing is also having the same model as the growing developer that is let's learn and do together right now you will be thinking that why are you changing it we can't see any change so let's change it to the name right so here I'll write name so that this time on update data I'm updating the name right so you see here we have the growing developer let's move to this here we move this on press and I'll write update data yeah we are calling the updated with update data method here save this and a chi update data and the updated data is now so I'm Singh and here also you can see that the data is getting updated so that's one for my side you have seen how we can add data fetch data all the crud operations have been done go ahead and play with the data how you want it once we move on to some real-life real-world applications we will see more complex queries on it and coming videos I'll also tell you how we can filter the results from the collection as well as the documents so that's all for this video hope you liked this video don't forget to go to our website and check out the all the latest videos and the blogs that I write show some support and go and follow me on other social platforms as well and that's all thank you so much for watching this video hope you're having a nice day goodbye stay safe
Info
Channel: The Growing Developer
Views: 52,358
Rating: undefined out of 5
Keywords: flutter tutorial, flutter tutorial for beginners, flutter, flutter tutorials, cloud firestore, cloud firestore tutorial, cloud firestore flutter, flutter firestore crud, flutter firestore tutorial, flutter firestore query, flutter firestore add data, the growing developer, firestore flutter, crud operation firestore, firestore crud, firestore crud example, firebase tutorial, flutter app development, firebase flutter database, flutter firestore
Id: lyZQa7hqoVY
Channel Id: undefined
Length: 24min 53sec (1493 seconds)
Published: Sat Jun 27 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.