 So, this is what our CROT application will look like. We've got three text fields with name, description, price. We are pretending we make some kind of menu application. And then we have the functionality, create, read, update and delete with our buttons here. And then we want to display our entries right down below here. And I've got one entry for now, a pizza, very nice and six dollar or Euro. And you can add more if you click on the field and then maybe burger, description, ice, price, maybe five, click on create and the burger gets created and gets automatically added below here. And then we can read out our entries by clicking on read. We just need the first right here and got burger very nice in our console. And we can update our entries by clicking on update. So, we change our description, super nice and our price to maybe seven, click on update and we see it changes to super nice and seven. And if we want to delete, we again just need the first field and then simply click delete and our entry gets deleted. I created a new project and the first thing we need to do is to build out our layout. This is our example application we always get when we make a new project, I will delete all of it and we will keep the main and delete the app. Then we use a material app and say the book show checked more to banner to false to get rid of the debug banner and then we use a theme, use theme data, give it the brightness, brightness dark, use our primary color, colors light blue and use 800. And an accent color, colors seon and 600. Then we need a stateful widget, so we type sdfull and call this my app and now we will start building out our layout right down here by returning a scaffold and give it an app bar. The title should be text widget and call it Firebase. Next thing we need is our body right below our app bar, body and here we use a column and give it some children and first we want to build our three input text fields. So we use text field, give it a declaration, input a declaration and our hint text should be name and on changed we get a string name and then we want to call a method called get name and give it the name. We will create this method shortly. First we want to copy our text field and paste it below two times and this or description call it get description, also description, description and this is our price, price right here and get price and price. So now we want to make our methods and we just simply say for now that we want to read out our values here and save them to a global variable. So make a string name and description and we need a double for our price and then get name, get our name, say this name equals name narrow here because we are, I'm sorry we are not in our state that's of course not right so put it right here. So this name equals name and then we just want for debugging purposes print out this name, get a description, get our description, we want to say this description, quotes description and print out this description, a last get price, want to get the price right here and then this price equals double, pass and give it the price right here and we're passing our string into a double and then we want to print it out, print this price all right. So we will start up our application, maybe we want some padding, I will add some padding to our column, there are an entire padding and we just move this and this and then we start our application, I added my app to our home here and our material app and then started our application and this is how far we got, so far we've got our three text fields and we just type in them now and we get our data displayed down here and in the next videos we will create our buttons and then start with Firebase. So now we want to make our buttons, therefore we go in our children's widget here and create a row and this needs a text direction, text direction LTR and some children of course and we give it a raised button, raised button needs a color, color screen for the first button and then it's child, text widget and we say create and then on pressed we want to call a method, to call a method what is going on, oh I don't know why he's doing that, so we want to call a method and call it create data and we will, I've got one too many that that was a problem, so we want to create data method and we will create this later but before that we will copy our button three times for our other buttons and put it right below and this one is our read button and we don't need a color because it uses our default color, default blue and we call this method read data, we'll also create it later and this is our update button, it needs orange, call it update and update data and the last one is our delete, need to be read and delete and delete data, so now we want to create our methods up here, first create data and we maybe just print out create for now, then read data, print out read and then update data and to print update and then delete data and we want to print delete so and maybe we can make this a little bit nicer by adding some padding because you know without padding everything looks very squashed, so I added the padding to our row here and to make it maybe five we have to look out a little bit for our sides, for the sides of our screen so it doesn't get too big and we want to add padding to every button, this is to be only right and we need to do it for the others too, only right, we copy this and edit here also, right here and last one right here should make it look a little nicer, so we restart our app and look at it and yes, so this is how we got so far and these are new buttons and you can check out if they are working, we've got to create it, we've got read, update and delete, so so far everything is working perfectly, now we want to add SQLite to our project, we need to go into our pubspec yaml and in our dependencies we want to type in sqflight any and save it up and close this file, we don't need it anymore and get all the dependencies and then we want to create a new package, call this one model and we create a new file, new dot file and call this one dish and this will hold our layout for data, so every time we want to create some data we will make an instance out of this class and this class will give us the looks of our data, so we will save our name, our description, our price and we will make this a class and we will always when we make a new dish, call this class and make a new object with our name, our description, our price but we'll talk about this in a later video again, so we close this one up, as I said this model is for the looks of our data if you want and then we create a new package, call this one and dbHEPA and rename it, rename database and to call this one database and create a new dot file and call this one dbHEPA and this file will hold all of our methods, we need to connect with our database, so we will have to create, read, update and delete all the methods will go into our dbHEPA and even more if you want to create our database and create our table, these will all be in our dbHEPA, so this one will hold all of our methods to connect to our database, so that for it, so we've got our model created which will hold the looks of our data and our dbHEPA which will have all of our methods, we will need to connect to our database, so now we want to make our data model and we open our dish start and we simply create a class, call this dish and here we need two strings, we need our name and our description and we also need one double for our price and then all we do is to create a constructor and simply say this name, this description and this price, so we always want to have a name, a description, the price when we call our class when we want to make an object out of our class and this is what we've done here so far, so again to our class model we simply need this to bundle up our data, so we use it to store our data when we want to make an entry into our database and this is one easy method how to do it, so we simply make an object out of this class and we can then simply save this object with our three entries into our database and that's what we will be doing in the next tutorials, now we want to create our database and we are in our dbHEPA.file for that, we first need to import two packages, sqFlight, sqFlight. and we also need our path, so we import path, path. Alright, then we create our class dbHEPA and we want to create a method called initDb, it's the asynchronous and here we need to make a string for this database path, it needs to be equal await, get database path, so we get our database path right here, wait for it and then we save it, so this is one predefined method where we can save our database to and need a string called path and we simply say join database path and then the name of our database, so in our case we can call this like dishes db.db, it doesn't really matter just important is the db, so it knows it's a database, as I said this is like a predefined method which gets us the location where we can save our database, so this is predefined and then we simply create there our database path, so this is then the whole path where we want to have our database, so then we make a variable called this db and we call await, open database, give it our path, then we need to give it a version 1 and then we want to call onCreate and onCreate we want to call onCreate method, we did not create yet and then we want to simply turn our database to return our db, so we want to wait to open our database and save this in our db and here we want to call onCreate method we will define in the next video and then we return our db, so in the next tutorial we will create our onCreate method, so now we want to create our onCreate method and here we want to create our table, so we call what onCreate, it's a database called stb and an int version which we don't really touch, so it's also asynchronous and here we wait for the following, we want our database to execute an sql statement, so in our case you want to create our table, so we simply type create table, this is our sql code called it dishes and here we want to give it a name, text description which is a text and our price which is a double and then we are done so far, our table gets created right here and then we return our database, so we can look at it again, so we create our path where we want to store our database then we want to create a variable database and what we want to call open database and we give it the path of our database and then we want to create a table and here we want to execute the following commands, sql command to create our table by create table dishes then give it our name, our description and our price, so nothing too fancy we could give it different other options like our primary key and an ID for example for our dishes but it's not really needed in our example so I did not include that but you can of course do that if you want to, so this is really just simple sql and you can run every sql command you know and want to write here and then if that's executed we return our database with our table next thing we want to do is to check if our database already is existing and you can imagine like when we start up our application for example our database gets created then the user saves data inside the database and closes the app off and now if he runs it again and we create our database again all the data gets lost so we want to check if the database already is existing so if it's existing we don't want to create a new one so we don't want to call init database a second time and don't want to return a new DB where we created new tables so we want to check if we already created a database and we need to do it the following way we create a database variable called this DB and then we make a future method and it's a database database get DB needs to be asynchronous and we need to get our async package to use our future and if we done that we can check if DB equals null so we want to save our database right here and we check if it's null so if we never created database this one here is null and if that is the case then we want to say and DB equals await init DB which returns as we know our database and our database then gets saved in our DB variable right here so this here is now saved our database and if it's not the case and we first need to return our database right here and if it's not the case else we already created the database so this is not null and then we simply also return our database we created for which was already saved to our DB variable now we want to create our different methods to create data read data update data and to delete the data and we will start with creating data I make a comment right here and create a data and we need to make a future and needs to be an integer so the return needs to be an integer and we want to create call it to create dish and it wants to have a dish dish dish and it needs to be asynchronously so when we count this method we will give it a dish so one instance of our class right here with our name description and our price and we will read then the data out of our dish and put it inside our database and we need to import our dish file right here so we need to import package flutter SQL lite so flutter SQL lite model and then dish start and our arrow goes away right here then want to create a variable DB ready and we simply want to wait until our database is ready and when that is the case then we simply return and we call wait again want our DB ready make an raw insert raw insert we need to insert data inside our database and you can use an SQL statement right here and want to insert into our table right here to our dishes and want to insert our name description description and price and we want to insert on the values and now we can use our string interpolation want to make it look like this so if we would hard-coded it would like want to put our values and for our example we can use maybe pizza so our name would be pizza and then the next value would be very nice and then next one would be our price so we would say maybe six so this is how it would look hard-coded and we then simply can use our string interpolation to write art and we can take our values here and then put it like this and just use our dish and name for the first one the second one would be our dish would be our dish description and last one would be our dish price like this so important you don't so you use like your single quotations here that's important that's our SQL syntax it has to be in quotations right here so and that is all we simply return and make our raw insert right here when we create our dish next we want to create our update data method and we make a comment update data and we need again our future needs to be an integer again so return and needs to be an integer and call it update update dish and it wants a dish again because we want yeah all of our data to be updated so we want to update maybe our description and our price and then we await until our database is ready and save it again await DB and then we return await DB ready and make a raw insert again just like in our create data method and here our SQL statement comes in again and we need to update dishes want to set our different our different entries and we want to set our description and our price so we want to check where the name is or we can do that first I guess so we could first check where we want to update and we simply say where name equals and then string interpolation and we want to take the name of our dish when name dish name and so we wanted to check if we got an entry where the name equals the name of our dish we gave it here and there want to set new variables for description set description equals and here in parentheses or string interpolation dish description and and then we need to make comma and set our price equals and single quotes so when we call our updated dish we give it a dish with our data our data is first our name so the name of the dish we want to update and we've got our description and our price so these both fields need to be updated and then we look in our dishes table where name is equals the name of our dish we just gave it so the name is name of the entry we want to update and here we want to set new data for our description for our description entry we want to make it equal like the dish description we have saved in our dish and the same want to do for our price want to set our price to whatever price we saved to our dish here and yeah we return it and that's all for our update method I tested out our application and I found one problem in our update dish method here I need to put our where name cut it out and place it behind our set I wrote that this way also in my previous code but I thought it would be look nicer when we had the where first but that is not intended by SQL so you get an error there so just put the where at the end and it works fine so this is our application also far with our functionality and now we want to create our pizza garden now we want to talk about our delete method so I make a new comment delete data and we again need a future by integer and call it delete dish and here we just to give it a string string name needs to be asynchronous so when we call it we give it the name of our text field of the dish we want to delete so we don't need the extra data of description and price because the name is enough to identify the dish we want to delete then we make our TV ready as always always need to do that wait TV and then we again return a wait and TV ready make a raw insert and we want to do the following want to delete from dishes dishes where the name is equal name right here so that is all for our delete when we call our delete method we give it simply our name of the dish we want to delete then we open up our database as always and then we execute the following SQL statement delete from our table dishes where you have the name equals the name we just gave you and then everything gets deleted what's connected with its name so what's in the same row of name now we want to see how we can read our data from our database this is a little more complex but also not too difficult to achieve so read data in the first path is always the same so we need the future and call it read dish and also just needs a string to know which data we want to read needs to be a synchronous and then say want to be ready await TV and then next we need to do which is already different we need to make a variable I call it read and here we want to save our results we call await DB ready and now we want to make a raw query so we don't want to insert something like in the other methods we want to query something out and we want to do with the following we want to select everything dishes where name equals the name we put here so my name equals name and now this simply returns a list of maps so in our raw query when you save this this is now a list of maps so we've got a list with different maps in it and you want to return the following return dish from map so we want to make a dish object from a map and we need to give it a map and we call read and as I said this is a list of maps when we save this in our variable and want the first entry so we read so get it the first entry so how do we achieve this that's that we can make a dish from a map we need to specify it so we need to create this method in our dish module so we go here and we say dish from map so call it like this and it needs a map map and we would just say this name equals map name and this description equals map description this price equals map and that's also let's talk about again so it gets a little bit clearer so our future doesn't need to be an integer of course needs to be a dish because we return a dish right here so sorry for that first of all and so we want to read our dish and we give it a name because the name is everything we need to read out our data from our database then we await our database and we make a war cry we want to select everything from our dishes table where from the roll where the name fits the name we gave it and we save this in a variable and we call it read and this variable read is simply a list with different map entries so if we had for example more than one entry with the same name so maybe we have saved pizza multiple times in our database which is not what we want but it could happen theoretically so this read simply would save everything line by line and make it a map so every row would be a map and it would be saved in a big list but for our case we will always have just one entry with the same name and yeah therefore we just always need to get the first entry but if you for example would would have multiple entries with the same name you can or read them out with this by just changing the number right here so this is the first entry we have in our list of maps and then we want to return a dish and we made our method dish for map and give it our map right here and this method works the following it needs a map and we gave it our map right here and then we simply say this name and read out our different entries so this name this name map name this description map description and this price map price and we make a map out of it make a dish out of it and return it right here now we want to add our functionality step by step to our main and dot and we first need to import our db helper and also our model so we can do that first then import our package then database and then db right and then we go to our create data method and we want to set our state and we make a variable what of our db helper and db helper so we make an instance and then we also want to make a variable dish equals dish so make an object here and we give it our name our description and our price name description and price and then we just call db helper call our create dish method and simply give it our dish and that creates data and we don't really need to set our state I guess so I delete it for now and yeah so we create an instance of our db helper then we create a dish out of our text fields so our name our description and our price gets bundled into an dish object right here and then we call our create dish method with our db helper and give it our dish so it goes right here create a dish this is now our dish we gave it here with our name description and our price and we await our database and then we make our raw insert in our table dishes with our name description price and we want to put there our name description and price which we saved in our dish object right here our update method is pretty easy because it's the same as our create data so we can simply copy this and put it right in our update data on and change this to update and that is basically also we create our db helper again our dish object right here with our name description price and then we call our update dish method so we go right here we've gotten our data here so we wait until our database is ready and then we call update dishes where name equals the name we gave it and our object here and then we want to set our description to whatever description we have stored in our object and the price shall be whatever price we have stored in our dish object next we want to talk about our delete data method which is even simpler to achieve and we just need to call our to create our db helper equals db helper and then we just call with our db helper delete dish and we just give it the name we have inserted in our text field which then was stored in our string right here so and then this method delete dish gets called so we wait for our database and then we just simply say delete from our table dishes where the name is the name we just gave you right here now we can talk about our read data method here we as always need our db helper and then the next we will create a future future form type dish so we need to import async and we also need to import dish of course model dish and save it and then we call this dish and call our db helper and say you need to read our dish and give it our name so this shall be a dish in the future and we call our db helper which needs to read our dish with a name we just typed in our text field and when that this has happened so dish then we get our database get our data back so I call this dish data we then print out then print out our variables so we simply or can do it like this we do our string interpolation say dish data name to put this of course in our brackets and copy it like this and then change this to description and price so let's talk about again so it gets a little more clear so we need a future dish and want to be want this to be a future dish and we want to call our read dish method and to give it our name which we typed in so we give this name to this method right here which which of course returns a dish so this is why this is our future dish because our method here returns a dish and we want to save it in our variable here so this has to be a future dish and we give it our name right here and then we make our work query where we select everything from our table dishes where the name is equal the name we just gave it and as we talked about this read is simply a list with different maps on it and out of this list of maps we want to make a dish by calling dish from map and give it the first entry because as we talked this is a list and we just need the first entry and want to make this map a dish and then we come here and make from our map a dish by simply putting our name description and price right here so and if this got executed and we in fact have now our object with our data right here in our dish then we can call then because this is a future and here our data of course gets saved and then we print our dish data name our dish data description and our dish data price out into our console so and this is our application so far and we want to test out our functionality now we save our pizza with the description very nice for maybe seven bucks you can create to save it and then we want to read it out can erase this so far and then click on read why why why why why why why why why why why okay so we managed our basic crud functionality but now we also want to add one more method so we can read out all of our data at once this can come in pretty handy and it works a little bit different but also not too complicated we are back in our db helper class and we make a method call read all and this has to be a future of type list and this list wants to have our dishes so we have our future and the future is of type list and the list holds dishes then we want to give it a name read all dishes doesn't need anything and we want to make it asynchronous then we as always need to make our db ready variable and wait for database to get ready then we want to make a list of maps and this we call dishes and we await till our db ready and then we make a raw query and we want to select all from our dishes table then we want to make a list out of dishes yeah maybe we call this simply a list and this will be our dishes we say this needs to be a list and then we say form and i equals 0 i smaller than list length i plus plus and here we say dishes dot add want to add a dish or list and here we want to call the name i will talk about this in a second and what our description and our price so this description and this price and then we of course want to return our dishes at the bottom so we make our list and here we will get all out of our database and and simply put it inside this list right here and then so this is a list made out of maps like in our read up here so a list made up out of our lists for our entries made up of our maps for entries then we make a list made out of dishes so want our dishes to be a list and we want to add some dishes to our list right here and then we make our for loop and we simply watch how many entries we have in our list so how many dishes were in our database and we add one and then we simply add to our dishes list right here a new dish and put here our list entry for example our first entry would be zero so out of our list for our first row the name the description and the price and make a new dish out of it and add it to our dishes list right here so our dishes list will contain objects so we simply converting our list right here list out of maps to a new list called the dishes made up out of our dishes so this is our list made up made out of objects and we had a list made out of maps before and we simply converted by going through our list and for every entry we have in our list we want to add one to our dishes list and we want to make a new dish depending on the role with the name the description and the price for the corresponding role in our list and then we simply return our new list with our dishes objects and in the next video we will see how to use this dishes list in our main dot now we want to make our read all dishes method in our main dot file and we need a future and this needs to be a list and this needs to contain out of dishes and we call it get all dishes needs to be asynchronous and we need our db helper of course and then we build our future list made out of dishes called this dishes db helper and here we simply read all dishes and then we return our dishes right here so um yeah get all dishes we here make our db helper and then we make a future list of our dishes objects and we read all dishes right here so we want to execute this method which returns our dishes which is as we have seen a list made out of objects and yeah we make this a future and then we return our dishes right here and in the next video we will use this output right here and display it in our widget tree i added a role to our application um below our buttons for our names directions and prices it's a simple role text direction text direction ltr then got three expanded as children and here we just have our name description and price so if you want to follow along this is basically how you can make this role and then we come to the important part on how to display our data and we need something called a stream builder for that and or not a stream builder a future builder because we have futures and it wants a list and in our case our list needs to be out of dishes then it needs a future and here we basically give it our data and our data is in our read data method no in our get all dishes method so we simply call our get all dishes method right here to get our dishes and then we use a builder give it a context and then a snapshot this snapshot will save our data basically and then we need to return list view builder and use shrink shrink wrap to this basically displays our list below our other items so our list get gets displayed right here then we need an item count and we say snapshot data and here we get our length so with snapshot the data we can access our data and snapshot data length to get the amount of items we have saved and then our item builder needs a context and an index this item builder will now build our our items depending um on the input and we simply return row here and we can basically copy our row up here so I will copy this row and basically just put it right here and we need to close this with our uh need to close up right here and then we want to do we want to get our data around here so the first one is for our name so we call our snapshot data and here we want to give it our index and then simply read out the name same for our description snapshot data give it our index and then the description and we copy this and paste it right here and then use the price and this gives an error because our price is double at the moment but we can't put a double inside a text widget so we have to make this string by putting two string at the end and this is basically our future builder we can talk about it again so our future builder needs a list with dishes and he gets his list with dishes dishes by our method get all dishes then our builder needs a context and a snapshot a snapshot as I said in this variable all our data gets saved and we want to return a list view builder string wrap to place it underneath item count snapshot data to access the data length to see how many items we have and then our item builder which will build out every row of items we have we give it a context and an index this index automatically gets higher and higher depending on the data so the first row get the index zero and then second row index one and we simply read it out so our first row will have for the name snapshot the data zero zero and read out the name for the description snapshot data zero description and for the price snapshot the data zero price and this will be done for every item we have in our snapshot and then the next row will get displayed we now need to set the state for our different methods right here so we simply set our state and copy and paste this right here let's do it for update data put it right here read the data that needed and delete data needs it again save it up and this is our application so far and when we click on create we see our pizza gets created and we can change it to super nice super nice click on update and you see super nice gets updated and we can of course read it out and also delete it by deleting it delete it and put it in again so very nice five bucks and read it out and we should yeah create it first and then read it so we've got now bits are very nice and five bucks so our lost connection yeah right so our application works so far we've got our different corrupt elements so create read update and to delete and we also have seen how to get all of our data and places in a future builder and simply listing out all of our data at once hey guys congratulations if you're watching this video you made it through the course I hope you enjoyed the course so far learned a lot and if there are any questions left feel free to ask me and yeah have a great day bye