Complete Quiz App With Timer In Flutter | By Desi Programmer

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
you tube this is Prince from DC programmer in this video we are going to create this amazing app that you can see it is a quiz application where we have a timer to so that when the timer runs out you have to go to the next question now while creating this complete application we will be learning a lot of topics such as more about navigations and routing set a straight time of functions time or periodic and how we can accumulate multiple things in a single screen how we can work with that we will also be digging deeper into JSON default acid builder we will be learning more about stateful and stateless widgets and we will have multiple screens help this is going to be a complete application and I have am recording this after creating the complete video so that I can put this on front and you guys can see what actually are going to learn in this company tutorial so without any further ado let's just start the video and let's learn let's create this complete amazing application all in just one video from scratch so you can see that we have an app up and running right now we see this error because we don't have a home right here still you see that the name is query stop this is the name that I given to the project and the theme is colors which is an indigo color that I have just recently fall in love with now I'm going to say that we need a home and this home is going to be a different screen so in library I'm going to create another dart file and I'm calling it as splash dot dot because I'm using my custom splash screen not the inbuilt is process screen so it's going to be a stateful visit an image as a splash screen let's save it and here just to make this work I have to import the material library swap the same port back is : flutter slash material dot dot then we will return now I have to just return a scaffold with a center with the text at Center that's it [Music] now having this is plaster screen coded which returns a scaffold with a background color of indigo has a body which is a center with a childhood text it says squeeze a star and the only style that I have right now is that the font is going to be of size 50 so here I have to just say splash screen and it will auto import that for me save it and now when I restart the application this effect should be apply to you by the time the application restart let's create another file and I'm going to call that as home dot dot Y home dot dot because this is actually the home where you will see card where you can pick a language and work with that so I am saying package : clutter slash material dot dot and this will have a stateful was it I'm going to call it as home page let's save it now here's this plaster dot and I think I should be changing the color to color start white and now it's a loop decent and obviously I have to use a time or so that after a particular second this is plaster screens or disappear I will move to the next screen for which I'm saying I have a timer and there okay actually I have to call the Unity State first I am saying override the interstate so add red override and the function that we are going to override is in it state and this in in this inst in it state we're saying first call the super since state and then started time' a timer for a duration which is going to be an seconds let's say three second and after this duration you have to do one thing there is going to be a callback function and in this callback fornicates is an error why okay it says to accept it one given fine so the second is going to be a function itself where I'm saying navigator dot okay it's not accepting this as a function which makes me believe that did something wrong which we are doing yeah this comma is outside it should be here and now if we give it a function which accepts a navigator dot of this context and I have to do a post replacement and here we need a material piece route so here's our material piece route where we have a Belger which will be it should take a corn text and what we are going to build is the home screen come on do we get the home screen it is in home dot dot it's actually home paste not home screen so I have to say home page it will auto import that for us let's save and now if we restart this it will make sure that we get this thing out of here so this is an error it says implementation of state dot build while we did implement a build state yeah it is okay now these errors so to go let's write let's try to write some code in our home dot dart and let's see what we get so this is how our home dot dot paste looks and here on my scaffold I'm saying that you get a body which is going to be a list view a list view and here we are going to give its custom visit the children is going to be visit and I'm going to name them as custom called wine so this visit now we have to code them so let's copy them and here we will be coding the custom visit visit a custom visit it should return a visit now let me tell you how this app functioning works is that after the splashes screen we see this screen and here I don't need a will pop scope because by default I am saying to get this screen as a replacement so when you say back it will exit that witch but on people on pop will scope we will need later on right here I have to say that since it's a return of visit I am going to say return some padding and this padding is going to be come on we are going to have some padding of heads insect dot all and a padding of 20.0 from all side now this padding will obviously have our child and that child is going to be inked well so that we can get the on tab functionality and then the inkwells child is going to be a material now material will give us things like elevation to let certain point zero and then we will have a child which will be continued to take some to take the entire space of the material now the card is going to be something like this big chord with the circle of char of the programming language some text and some description so in this chained container I'm going to need a child which should be a column and in column I'm going to need some children first one that I need is again obviously up guiding with some parting thoughts as insects dot symmetric and I only want some vertical power padding so I'm saying vertical at 10.0 fine let's save it that the child is going to be a material again and the materials child is going to be a container and the continuous child is going to be a clip oval which means clip the thing in some oval area we get a child which is going to be an image where we have an MS which will be a set image which gives us a question that where are our asset teammates so let's start inserting all the assets that we need and here there are three different types of assets that I'm going to need the first one will be a JSON file and if you don't know about working with JSON file in flutter you can watch my previous video click on the I button right now it you can go over there the second one is going to be a some simple font and you can just download these TTF files which is true type font from any website most of them are free and then we are going to need these all images which have their own work and you will know about them sooner or later so what I'm going to do is that I'm going to copy these folders and they will be available to you so you don't need to worry and I'm going to paste them and this good star let's just paste it and that's it we have the assets but we need to tell our pub spec dot yam all that I have a few things to use first of all here let me write that I will be using something like images slash everything in images we'll be using it then we'll be using everything in assets so this is done exit code should be 0 yeah let's talk about fonts so fonts are going to be like let me just get this uncommented the family is going to be quando and the font is going to be let's just take a look right here this is the name that you're going to read so the font is going to be fonts /q un t/o dot t TF let's save it and exit code so it still zero if it's zero that means this asset exit exists and we can work with that we need other fonts too so all that I have to do is to copy this and then paste this it in paste this in this particular level next one that I'm going to use is satisfy so satisfying and the asset is satisfied or TDF and the third one that I'm going to use is alike and the asset is alike regular doe GTF now see although I have these fonts here but the problem is that they won't be accepted by this app at once okay why it is so is because sometimes it does sometimes it doesn't so let's say in my home dot dot file if I say that this quiz star will have a style which has a text style where I'm just saying that I want to change the font family to something like quando let's save it and let's see if it reflects or not see no reflection well in that case you don't have to worry this won't be reflected many times so just use command shift P use clean project it will delete an existing application and then all that you have to do is to rebuild the application before that let's get rid of this error what it is actually and here we don't have an asset image so let's just say for the time being I wanted miss of Python which we have here it's PI dot PNG so I'm saying images slash PI dot PNG let's just save it and let's rebuild the application now after restarting the application just as you can see that the font has changed for awkward stuff so even here so whenever you are working with this and if the phone doesn't work just clean the project Restall it reinstall it and good to go now having said that I want to change the font family here too it should be satisfy and I hope the spelling is correct if it is not we will check later if it's correct or not now here I need to give some more properties to this and these are just redesigning it it completely depends upon you what you want to give or not like here in border-radius I'm going to say some border dot circular and come on border radius dot circular and 20.0 let's save it and here now you can see it's a little bit circle I don't want much I think 20 is good for me then here in this container which contains this image I'm saying that the height should be just 200 and so should be the width just 200 let's save it and I hope we should be giving values in doubles so here it is just 200 now this material 2 will again have some elevation which is let's 5.0 now when you save this this should appear a little bit raised up and it does but right now it's a square I don't want this right now it's a square and I want this to be a circle now for that all I have to do is to give same border radius to what my container and material and my job will be done so I'm saying border radius is border radius dot circular and since this is of width 200 it should be 100 point 0 give this that's cool and I have to give my container to the same thing so I'm saying even if I don't give it won't affect much I hope I'll just save it and let's move forward with this now actually this big container I don't want it to be off-white for this material we'll have our color and the color is going to be colors dot indigo I hope indigo looks good yeah if it doesn't then we will go with something like Lu okay indigo looks good I'm saying indigo indigo accent that should look pretty good fine now moving forward after this circular avatar all that I'm going to have is another text a simple text which should be the title for this so after this padding okay after this padding remember make sure that these things you're writing at the correct places I'm going to have a center visit which will have a child which will be a text a text which says let's say right now python let's save it and here python appears but in a way that we don't want right who wants python to be like that so I'm going to give it some style some bear some bear styling the textile but I'm going to say that the font size be something like eighteen point zero it should look decent not right now let's say twenty four point zero then I want to change the color and font style so the color is going to be colors dot white undoubtably the font style is going to be okay the font family is going to be something like let's say alike if it's look good it does a little bit then how to say font weight which will be font weight W 700 I think it should like it should look bold enough and it does after this Center again I have another container and this container will contain some description so this container will just have some padding from all the sides as insects doctor that's a twenty point zero it will have a child which will have them text and this text will just contain some this is some random this corpse come on forgive me for my chopping speed if it's low and I want it to be of slits or some particular characters like 50 or 100 and then here I'm saying to go to style for this text style come on to a heaven problem yeah it should be inside this not over there so I'm saying style which is going to be some text style now here I need first of all some font size 16.0 is decent and okay some color so color is again going to be colors dot white that is again okay or if we can go with grade too if you want and the font family that I'm going to use is actually alike over here here I want to still go with quando it should look good yeah it does Python and then we have this after this alike I'm going to give some particular properties to this text visit to which is like mmm okay just forward max lines max line is going to be five okay then I'm going to say things like texture line will be text align dot justify it looks little bit decent and then you can just add some random text over here and I just want to make sure that the number of lines are not more than five so now if I save this it will show one two three four five lines which means if I add another line it should not show that so if I save this it doesn't show those many lines so yeah this is what I wanted and I can force my user to give only little bit description but since this is going to be controlled by the developer himself I don't think I need to force much on certain issues like this right anyway now moving forward of days I just want such more cards so that's very easy before that let me just change this to eighteen so that it looks a little bit decent which it does right now now since all that I want is just same cards on I don't need five cards so I'm just going to say this five time save it and here we have a nice cards back over here the only difference is that all of them say the same thing which we don't want so let's walk with them let's let's first work with the title so I'm going to say that they will be providing us some title like it provides Python this provides Java this javascript this provides c++ and this provides let's say any particular programming language let's just see that's completely up to you the stooging part of what they're going to provide now this source error because here we are passing some value but we are not accepting here so let's accept it here and it's going to be a string and let's say the name is going to be clang name which stands for language name just copy this and wherever you have placed this Python just paste it over your save it and boom here's the magic C Python Java JavaScript C++ and C the next magic want to see let me show you I'm going to create a list of a string okay I'm saying that I have a list of string come on as T Rin Z list off a string and I'm going to name this as images and this is going to be a list obviously now this list is images slash PI dot P and G save and I need four more now what are those images like what I have a name they obviously I don't remember so after PI dot PNG we need Java which is Java dot PNG then we need JavaScript JavaScript okay it's GS dot PNG then we need C++ that cpp dot PNG the last one is actually Linux dot PNG you can see right here so all I have to do is that I have to go over here and this C has have to change this to Linux let's save it and now I'm going to pass another string which is from this images and this is the value that I'm passing images 0 now if I want I can pass this or even if I can't but you know see passing will make the things a lot more easier which is why I want it so images and come on charged images and here I have to pass the index of one let's just copy this thing multiple times I know these things make programming boring something you're like oh this is the task what I have to do it of all times and right now this isn't good alternative that's why we are using it so one two three four we gotta even use list builder but they will have just made this thing more complicated now I have another thing which is string let's say image and here just replace this with that let's save it and let's see what happens do we see any change no okay why not so I'm seeing here images slash PI dot PNG and then this and then here I pass a string which is images 0 then 1 then 2 then 3 then 4 and here I'm accepting them and the asset image is going to be this a string image which obviously will give a different address every time so let's restart and see what is happening as you can see we have this ok now we get these amazing things obviously some of them look a little bit scaled up for which we can use the fit that it provides ok not for Chad Chad Chad images provide us fit property and I'm going to say box fit dot cover come on box field dot cover let's save it and let's see how they look okay is there any change okay next time when you restart the application it should give us those changes box fit contain okay no change in changes yet when we restart the application we will see the changes but this is what we have right now we can tap on these cards and that will make these cards work like here you can see in the inkwell if I use a property on tap then here in this function all that I'm saying is debug range and all that you have to print is card job now let's just save it and check just click on this and it will say card up take a look right here I'm clicking it says card tapped card chap to come on again it will say Cod tap now let me just restore the application one second let's show you what we have as of now so that we can move forward with this here we first you see this a screen which says quill star in fancy way and then here we have all these images which Java just looks a little scaled up rest of them are pretty decent if you want you can change the background color of the card if you want you can change anything and everything that's completely up to you know forcement right now but this things look producing other they want is that when somebody clicks on any of these it should move to the next screen which I call as quiz space dot dot so I'm going to say quill space dot dot a new file where I have to obviously import a package which is material dot dot but the problem here is that actually in the quiz paste or dot we are going to have a scaffold whose body will contain a quiz page with buttons now we are going to use future builder to make sure that we X we get some data from Jason but this future builder is dynamic and it is a another stateful visit so whenever we make changes to this state this we'll be called again again again which we don't want this was the what was the issue that I addressed in the last video when I was talking about G stands for that all that we have to do in the quiz space is that you have to first code I state less with it let's say that this is get JSON and this visit should call that another visit so here I'm in the home dot dot I'm saying when somebody chaps on this I want to call you I want to call him at the method so I have to go and say navigator dot off context dot post as a replacement because don't want to come back remember when somebody starts a quiz I don't want the person to exit it any time as you want so a material phase route pays route that will have a builder which will for this context call this another page which is get JSON let's say which now here the get JSON is going to play a very important role the get JSON will just in return our future filter a future builder which will have our future obviously and build oh well the future is default asset under and we have already talked about this how this work default exit bundled out of context and load string and the string is a SS e TS / and i have only one string right here which is python dot JSON so python toward json now in the builder we are going to have two values the first one is going to be the context and then we have the snap sort and it should return something now that i'm doing doing what i'm saying is that if okay first of all we need to get the data now this date I'm going to accept as our variable right now let's say variable my data is equal to json dot decode and the source is snapshot dot data dot to a string and that's it and here I'm saying that if my data is is equal to is equal to null if this is a null do something else do something else so if this is null return a scaffold that's it see the game here I'm saying return a scaffold a scaffold with a body of center with a child that's text and this text just says loading that's it okay just return a scaffold because you have to return a visit so scaffold is a visit now the earl's case we have to return on the visit and this visit will take care of the entire pace of working and the UI of the entire page which is going to be a stateful visit so this is going to be a stateful visit I'm going to call it as quiz pays and this quiz pays should be returned here so in the Al's case all that I'm saying is that return this quiz space okay that's it you can just call here so we have to say return quiz space and that's it this quiz space being a stateful visit is also a visit so my job will be done we'll get the data in this video but my data and there will return the quiz page now one more thing limit let me explain you the complete working once again okay we get the splash screen which disappears on its own then we get come to this home page fine now when somebody clicks on any card on this home page okay all that I want to do is that I want to go to this particular page which obviously shows nothing right now then when you come to this particular place see I go back and it exits because I was using post replacement but when you come to this second particular page this second particular piece there we get some data in the quiz face now whenever you click on any card whether that's a Python oh that's of Java or well that's of C plus row if that's of Linux or anything all that's going to happen is that okay did I open the wrong application let's just close it and restart it by the way all that's going to happen is that all of these cards are going to take you to the same screen that squeeze paste or dot so all that we have to is to pass data to this quiz based ordered in this class of get JSON and this will decide which asset we have to read so here you can say that you are going to have a list of assets which will be a string obviously and that string you can just replace here and this will make sure about the asset that it's reading with it's pythons are JSON its Javed reducer and so on in this complete video will be going with Python JSON obviously but in this with the complete source code that you will see on github I will use different and other JSON files too so when this is done all that we have to do now again is that now this complete class takes the data which is from a JSON file in this complete class has to use it so all that we have to do is to pass the data from this class to this particular does class which will give us an error actually what's our and things that run this class only once so although this data is dynamic this variable my data is dynamic but when this is passed in this class it becomes a static which means that if I pass it as a variable then here it will be accepted as a string which will cause the problem so let me first show you the problem and then I will show you the solution here by the meantime all that I have to say is that don't return a container return a scaffold come on return a scaffold and this scaffold is just going to have a body which will be a column a column with children of different expanded okay here again we are going to work it expanded three expanded the first expanded with the Flex of for the second expanded with the Flex of six and okay it should be actually three and I think that's enough the third expand with the Flex of one for holding the timer's value now this three is going to have let's say for the time just to show you how much space they are going to have I'm saying that they are going to have a container with a declaration of box declaration only then this container will act as a box and there we will have our color it should be let's circular start red for the first one now the same thing I have to copy and how to paste everywhere that's it let's this being green and this being teal let's save it let's now click on this and here you see we are getting these three things so this will contain all the buttons this will contain the text and this will contain the timer so I think that's very easy for us actually so let's just do that this will first contain the tags for the child obviously should be a container but not with this decoration okay here the container will have another child which will be a text visit and here we saw silver something this is a sample question which will be displayed okay and now let's just save it obviously it's not going to look good so in the container I'm going to change the alignment first and this is going to say alignment dot and this is going to be bottom left see bottom left and this is it's being displayed which gives us another problem of not having any padding so I'm going to say as insects dot all and let's say fifteen point zero and it will be good see now this appears over here more things that we want is giving text style to this so I'm saying text style and right here I need some values first of all I need the font size which would be 18.0 I think it's a loop decent it does 16.0 to will do but see when I add a font family let's say quando C it will look even more increased in that case how to decrease this to sixty so that it actually looks good then after this I don't think I need anything else it's already looking pretty decent let's come to this flex and this flex here we have a container we don't need this decoration now in this container I need another column okay okay it's I will first need a child the child will have a column now this column we are going to have four buttons and these four buttons will show us the out will so was the options to be clicked now I'm going to call them as choice button which is going to be a visit something that we haven't coded yet we'll just copy this let's go over here and here I'm going to call that visit so wizard choice button which come on not repent boundary which returns some padding so that there is some difference and that padding is Ed's insects dot symmetric then we have some vertical padding 10.0 will do the job then we have a horizontal padding that should be lets 20.0 then the padding we'll have a child which will be a material button so that we can customize it as much as it as you want the first property that you obviously need is the on trust let's have it the second property is a child which should be text let's say for the time being it says option one let's save it and let's see what do we see if we get this material button fine now let's add more properties like color which is going to be colors dot indigo let's save it look at this is how this looks now indigo is too bright let's indigo accent it looks a little bit decent which again says that we have to see some properties for our text which is text style first thing that we obviously want to change its color which will be colors dot white then you want to change the font family and I'm going to make it alike let's save it and this is how it look let's say that the font size is going to be sixteen point zero only if it is decent which it is and then let's talk about the buttons own width and height after the color I am going to say that a button is going to have some minimum width which is 200 point zero and it should be decent for all the Isis and it will have some height let's save for 2.0 save it and let's see how it looks ok it looks a little bit decent let me just increase the height so that I can make this button or a kangaroo so for that I'm going to use CF which is B round rectangular border with the border radius off border radius dot circular and I'm saying 15.0 does it repletion let's see a little bit let's go with 20 and it should look more decent which it does right here see option one and prove descent now when somebody just never see the normal is flask or that a one should be a more brighter like it's not a more brightest or a more darker actually so after color I'm saying that this plus color should be colors dot indigo accent but with 700 and now one click on this and say it becomes more taco and I think I should actually remove this indigo accent right here indigo will look more better right click on this and it goes like this why so let's say it was seven it should be like this because of the highlight color so we have to say highlight color is also going to be colors dot indigo and this is again seven and drill let's save it let's see yeah it just becomes more darker so click on this it becomes darker so here I can send ago accent and now let's trickle or click on this and it becomes darker which is good to look now let I want is for search buttons so save it and here we get them and to make sure that they are at the centre you can we can do a few thing in the column I can say like main axis alignment is main axis or I'm at center and if you want you can even remove this padding and you can say that these buttons should be like let's say mean X element is going to be space around space between space evenly and they will take care of them but spaced evenly will just give too much spaces space around be more like this and space between will be little bit decent but not much okay it's not even that decent so that's why I'm saying just to go to Center one more thing that I would like to address is that here in this text I want this additional style in this text visit which is max line and here the max line should be only one only one line is allowed in the choice now coming to the last flex all that we need is just a text so let's remove this that's a child which will be Center another child which should be text and this is the text which will be displayed so let's say that the timer is thirty by default so this is how it will look thirty two small right so let's go with style let's change it with text style what I'm saying that font sides would be thirty five point zero which is a decent and this should be supported on all devices then I'm saying font weight which is again going to be font weight dot W seven hundred this is more decent and I'm saying font family which is going to be actually Times New Roman it's available by default so it should work come on and then let's just save it and this is how it looks right here so for the container I'm just going to say that the alignment should be Li Zi and M E and G alignment dot top okay so top left top right I just want it to be a top come on top Center that's it so this is how it should look right now top center although it looks a decent it's somewhere at the top center so I have four of my buttons and this is the UI of my quiz okay this timer will start running it will keep decreasing once it goes less than ten it will be red then this question will be changed this options will be changed or if you click any option in between then something other is going now I'm actually tired of recording so I'm going to break but this complete thing is going to come as a single video now that we are back there are a few things that I have that I want to do with this the first one is that I want to force this app to stay in the portrait only and not to go in the landscape now for that all that we use here in this build context aids system chrome dot set preferred orientation and here we can pass a list of orientation which is preferred orientation for me now for me I just want to have a portrait which is so I will say device orientation dot portraits down and device orientation dot portrait up that's it now even if you rotate this screen it's going to stay in the portrait mode only the first one the next thing in the quiz space dot dot I want the same thing so here too I will just say that this system Chrome dot set preferred orientation and here all that I have to say is device no it should be a list actually should be device orientation dot portrait town and device orientation dot but right up that's it now if when you rotate this it won't just move let me just try to rotate and so you what happen see it just stays like this only we'll just come back come on to have to rotate it one more time okay now the next thing that I want here in this quiz space when you click on this then we go to this quiz space now here I don't want people to click on this button go back because that's not ideal thing right yeah in within a quiz what if you just press this mistakenly at the term all that I want here is that let's just flip pay close attention to this this is the scaffold code from here to here we have the scaffold code so wisely start from the S of the scaffold copy until this don't copy the semicolon just copy until this actually cut this and then here we have to say ready turn will pop scope that's it here first let me just quote the child and this is done we won't have any problem now in this on will pop scope I am saying on will pop we just want to code this which will return a so dialogue and the sword dialogue will have its context which will be context and then it will have a build job which will be alert dialogue let's say for now and yes actually we have to pass the context I will say builder for this context will be and come on alert dialog and alert Allah will have its own property obviously the first one is going to be title which will be text and I'm saying the title is nothing else than just quit start it will have some content which will again good text what I'm going to say you can't go back come on I don't know why we're not record a video my typing it just miserable at this stays ok then after the content we will have accent which are just going to be flat buttons with a non pressed that I won't say what it does right now but then we have a child which is going to be a simple text research which says ok I understand what you want to say let's save on this let's click on this and now it says this you can't go back this is just click on ok nothing happens because nothing should happen so I'll click on this again and all that we have to do when somebody click ok is that I'm saying navigator dot of context dot pop that's it save it and just John click on back click on OK and yeah you're back to this now moving forward let's first try to understand this JSON file now if you still don't understand if you don't if you think this JSON file is too complex to work with you will have to first go and check out my tutorial in JSON because then only then you will be able to understand this right trans simple what you can say that we have a list of object the first object your set of question to separate second object contains another map of options and the third object contains correct chances now this thing when accepted over here will work well but only difference is that when we pass data from this class to this class this will become starting and will become just a string so instead of saying what I have to say I'm going this except this my data should be a forced list only which it will be because this returns a list I mean this will be a list in terms of dot then here in quiz space I am saying pass some data with the key of my data it will be my determine now we have to accept it over here so let's say we have some variable my teacher and all that I'm saying is that quiz space will accept these value and the value that's going to accept is going to be first of all our key which will be key than a required value which is this dot my data and then it will accept this both and then here we will pass the super mat super key which we say the supers get the key as key come on small key yeah it's okay now this is okay we will get this data and this now I have to pass this in the quiz page state - so your unseeing pass my data we have to accept that here so let's say variable my data and then underscore quiz paid stay each and all that we have to accept through a constructor is my data so let's say this dot my data okay no errors as of here we are good to go so we'll get my didn't know that now we have this complete JSON and the only difference why I'm using two videos over here is that I don't want these methods that are going to code because for this application to call my future build up multiple times which it will be if I have coded this in this scaffold because that is a stateful visit already now moving forward with this in the choice buttons I want to show some choice let me just show you how this thing works it's very simple let's say that Shui let's say I want to show the first question so here all that I have to say is first I have to say my data then my data will give me question let's say 0 will hold all the question and if I say something like 1 let's save it and it says it ok it says that the method that was called are null and there is no such method let's try to repress it so that we can get this and I hope it should worked when we refresh this ok as you can see it's working we just refreshed and now it's working actually when you are communicating between classes you will have to restart the application now see we get the first question take a look at it here this is the first question that we have this last and are invoked right here now how to get this first option now here actually what I'm going to do I'm going to pass some key see here these are the keys ABCD that we are using so I am going to pass some string which is going to be a b c and these ABCD are going to play a major role it will come to know very soon so in the come on where is my choice button i'm going to accept a string let's call them k and now this option should be displayed for which i am going to say something like my data then now i have to go to this first object there the key will be 1 and the value that i want to show here is for this k let's save it let's see what do we get get these options out of this see these are the options double P triple P 3 P and D 3 and we get them now that's good like we have these detail right here now when somebody clicks on this they should obviously go and check the answer for which I'm saying that when somebody presses this call a method which is check and so and check answer doesn't exist and we have to pass this pass this check answer this key value so I will have to copy this and then I'll have to code this function here also void check answer which accepts a string let's say SK itself and now this should calculate the answer but before I do that I have to make sure that when somebody presses on the correct and so the dis so turn green and when somebody presses on the wrong answer then this should turned red and then again it should come back to its original state and before that I want to make sure that this timer is running when somebody starts that but this time I am going to deal with the time at the end because if I start right now it will create a lot of mess so first let's deal with the buttons now for that we are going to need certain colors so I'm saying color which will be color too so is going to be colors dot indigo accent come on then I'm going to need three different column one is going to be right this is going to be wrong when things are right then the color should be green it's wrong the color should be red that's okay next thing that we have to do here is that in our this function check answer all that I'm saying is that if if the even button is pressed let's say this button is pressed then this will be called in this string key we'll make sure that we get the same value that's being displayed here so what I'm saying is that if the answer is correct then we just need to say like yeah you can proceed answer is correct so and so these are the second place and then I have to say and sort of let's say one if this is equal to actually it should be converted to 20 to convert to string know if this is equal to my data at one and I'm talking about option where we again have one and here we have K come on then here we have K if this is the case then that means that the answer is correct and I have just messed it up let me just see this is okay this is okay okay okay everything was okay now if this is the case then what do we have to do first of all let's say that we have some integer marks for marks let's say int marks come on let me come down over here these are spacing that are just disturbing me so here I'm going to say I have some integer March which are going to be zero by default and then if this is the case which means that the answer is correct so first I have to say that increase the marks which is going to be marks is equal to Mark's plus five save it and then I have to say that this color to saw should now be right okay while in the else case when this is not the case all that I have to say is that color too so will now be wrong and then I'm saying call the set stage and tell it that button color is now this color to source so that it can be changed for which this button color too should be a variable which it is not right now now I can't change the button color variable right here directly because there are four different buttons so let I need is a list of button color to be displayed to each and every button with help of this key what I mean is that I'm going to create a map okay a map of nothing else but a string and color and this maps name would be lets say button color BTN Co Aloha and here we are going to have 4e some color let's say colors dot indigo accent yeah come on now that I'm creating a map I don't need that symbol okay so color dot indigo accent and the same thing but this key should be changed to B C and D now let's save it let's come down here and in this choice button in this color we have color indigo accent and now it should be button color with the key that's key save it and there will be no changes right here right now but what happens right here is that I'm saying change the button color of that key which is press right now and set it to color too so now what now see this is going to print P three times if I click on this button see it becomes green right amazing right click on three P it becomes red but this is not something that were not even obviously I don't want people to click on multiple options at once and we are going to deal with it don't worry hold tight now after this is done I want to move to the next question which again raises certain issues like how do you do that now for that I'm going to use another integer I and it should start at one y at one because here things start at one not at zero what I'm going to do with this integer is that see take a look right here okay where is that take a look right here this is the question now this 0 is constant but this is that which is going to change so all I have to say is that I dot 2 is string so for the first time this will be the first question moving again here you will see everything is going to be same but this option that we are showing this one should be changed I mean if they change this value we are moving to the question so I'm saying IDOT to a string over here to now this will do the job for us so all I have to do is to code another function let's say white next question and I hope that my spelling is correct now what I want to do here is that I have to check the value of I first let's that you want to show just five questions I'm saying if I is less than five increase it else in the earth spot I have to say like go to the next risk and right now I'm not doing the other lot I'm saying is that if eyes less than five just increase it but I'm not going to just call it in this way like I want the user to see this effect for some time and if I just call this function right here then this like like just as user presses this button it will just fluctuate to be green and just pass which I don't want what I'm saying is that I am going to use time or here and how to say wait for some seconds and then do this so let's say that the duration is in seconds and I'm saying wait for two seconds and then call the function which is next question come on next cool save it at ten am now it will work I mean just as we click on this it will wait for two seconds it will call this I again it's not doing right now but it will deal with that just okay see it did call click on type and one - wait do I have to refresh with this every time we'll deal with that okay we have to call the setter state actually so we should be doing this within a city state actually so I'm saying cert stage then do this now everything will be good click on function and after two seconds it will go to that but after this even I want to reset all the colors back so button color with the key of a should be said two colors dot indigo accent and this is something that we have to do three more times come on let's do judge semicolon semicolon two more times and it should be the first a then B then C then D now let's save it actually us restore the application so we can see everything from the beginning at once so let's click on this card and see now this is the thing when I click on this this is the correct answer it stays green for two seconds so now I have the next question all buttons are reset if I click on find this is the wrong answer it just stays red for two seconds and then we see the next question obviously the timer is not working but don't worry don't worry don't worry I will get this done for you in this video itself and now it's the time to actually code the time of function which I'm saying to be as void start timer it takes no argument but but this won't run on the main thread because if it does run on the main thread then it's going to cause problems like it will wait for any input or output and I want it I just want this one continuous on a different thread so that we don't have a problem so this would be an asynchronous function so I have to say acing and since this is an e synchronous function what means is that there's a start time I will run on a different thread so no matter what we are doing in this main thread this won't be affected and here all that I'm saying is that I want some constant second let's say one second which is going to be a duration in seconds which is one then I'm saying that I want a periodic timer so timer dot periodic it will have a duration it will hard it have a callback the duration is obviously going to be once again and the callback is tricky because here I have to call and here I have to pass a timer again that's a timer T and in this callback all that I'm going to do is that I'm going to call the set stage and I'm saying start checking for this value now this is by default 30 so I'm saying in T so timer is equal to 30 fine then I am to have a string which will be so timer which is going to be 30 by default now all that I have to do right here is that let's check for the values if if the value of timer is less than one yeah what I have to do is first cancel the timer because if you don't cancel it it's going to create create a lot of cancer problem and the timer is T right here so T dot cancer we see if you don't cancel it it will keep running on different third which means even though we want this to run per second it will start behaving like 30 29 28 to fast which is which is a very big issue then else in all different conditions all that we have to do is to decrease the value of time or solid I'm saying is the timer is equal to chimer come on minus one and then after calculating this set the value of so timer to timer dot to string also after this like when this timer just runs out of time then first canceller time off then call the next question because you obviously like we would like to so the next question now before jumping ahead to see what's happening let's come over here and here this thing which is 30 let's change it to our value which should be so time off save it and there it is still it won't work actually as soon as everything loads we want to start our timer by default right so for that you will have to call wild init stage where I'm saying call the start timer and then super dot init state and this should be over I did so I'm saying at rate override let's save it let's restart the application and let's wait for the amazing output here we have the splash screen which has quit star now let's click on this and let's see how many errors are we getting no errors see this runs whoa it's walking it is like 27 26 25 24 23 and so it will keep working and as soon as it goes to 0 you will see that this question will be changed by the time it's working let me tell you all that we have to do now is that when somebody presses this button in between even then we have to cancel the timer because if we don't then it's going to cause a problem for which we are going to use the same method that we used in our timer application but let's pay attention C 0 and question changes now obviously in the next question all that I have to do is I have to say that this timer is going to be 30 again things just have you know you can't remember everything so in the next question we have to and by the term remember I mean you can't remember the complete road map so how to again set the timer back to 30 and one more thing that I want to say is that we need a boolean value a boolean value which it will be canceled time or which will be false by default all that I'm saying is that when somebody presses on this button here called the cancel time or make it true so that this time was canceled and here a before this else we are going to have other condition and else if condition which will be that and the else if condition is that if the cancel timer is equal to is equal to true all that we have to do is T dot cancel that's it I don't have to worry about anything because this will take care of the next question obviously but it will raise to some questions like what if somebody presses on this then it becomes true and it will astray true from it for infinite time so we have to say that cancel timer should become false again timer should be back to 30 and after doing this all start the timer man that's it what are waiting for just to store the time or after this everything is done we will take you of this URLs part later on and I hope everything is good everything is cool it's just up and running let's just restore the application for one last time and this time things should work as I have planned them to so here we have our amazing material is blast screen let's click on this and now we get these options I'm saying Triple P is correct see it becomes green after 2 second it cancels see it starts again everything's cool up and running I'm seeing fine now this is wrong it becomes red then again it's started from 30 again we have we got the next question let's click on def it's again correct we go to the next question the timer starts from 30 and this is just a means you can just look at this how amazing it is right and now what we have to do is very simple we have to code another page which is going to be result piece for this so let's do that in the library I'm going to say plus this is going to be result piece dot dot result pays obviously up go to import come on I should learn spelling sometimes I think package : flutter slash material dot dart and it's going to be a stateful wizard I'm going to call it as a result pace and it should not return ask it's a return s calf fold actually with an app bar which will have on a bar with that title which will be a text it will say results come on results as string not results just a result let's save it and obviously it won't be reflected right now so what I have to do in this quiz paste or dot is that else if this is done go to navigator dot of context dot push replacement and here we obviously need a new material route so I'm saying material pays route which will ask for a builder which will take a context context and it should go to result phase automatically let's just save it and see as soon as it will run out of this value like as soon as this question will become I will become 6 it will call this method for me I don't have to worry and I hope she just calls it for me let's see what happens 0 see it calls the result phase now let's quote the result page as soon as we can the body is going to be a column with children which will be expanded obviously with a flex of 6 the first one will have a flex of 6 and let's not talk about child right here and I know these errors will come let's call them first another with the Flex of for the first flex of 6 we'll have our child and this child is going to be a material I just want to show an image so come on child which will be much easier with another child which will be a container with another child which will be a clip rectangle rectangle image and this clip rectangle image will have its own child which will be an image and this image will have an image which will be an asset image and this asset image is nothing else but this let's talk about good dot PNG so it's images slash good dot PNG let's save it and here we will see this image this will have a child which will be a row basically which will have its own children which will be an outline button with child of text that says continue and on press property to obviously since we don't have the on pressed property it is disabled let's save it it's enabled for the ro how to say that the main axis alignment is me Nexus element dot Center at will of descent and let's talk about its height and width and all do we have some color okay let's talk about border color border sight this border side will take boarder side or not end border it should be bought side and water side will have its own values like width and color so let's first talk about width should be like what 5.0 color should be like colors dot indigo accent let's save it and let's see how it looks this is how it looks five is too much I think let's go with three let's make it indigo let's save it let's look a little bit decent I just want more padding so I will say padding which is going to be as insects dot symmetric vertical 10.0 horizontal 25.0 let's see how it looks a little bit decent let's check the text style too I know this might feel boring but all that you can do is to skip because those who don't know this is for them this is going to have a font size let's 18.0 let's save it and yeah it looks decent UI Docs it does look decent we can change this PLAs color and highlight color too let's say that the splash color is color dot indigo accent let's save it now it's like this mm-hmm pretty cool it looks good I mean obviously was going to press it and hold like this now let's talk about this thing I mean I just I don't want this to be these hues this container won't have a clip rectangle as a child only out forward okay it should actually how a complete column okay this column will have its children the first one is going to be this clipped rectangle let's just save it okay now it said overflown by pixels which I always knew let's say this is seven now this container I'm seeing will have of width and height width of 300 point zero and height of 300 point zero okay I don't want I should not be giving this width and all to this container I should just cut this then I should come to this child this clipped rectangle the first one this would actually cut this - oh come on it should be our container again container with a material and this material will have a child which should be a container it should have a child it should be clip rectangle it should have a child it should be an image it should have an image it should be an asset image which should be images /good dot PNG this is what I want just save it in this container I'm going to say that the width is 300 point zero and height is 300 point zero let's save it and let's see how it looks okay this is how it looks I think it's decent enough to work right yeah it's decent enough the next thing that I want after this container after this material actually is a center visit with a child which will be some text and it says you let's say I'm talking about marks you scored 50 marks okay let's save it this is how it looks obviously not good but - who cares we know what to do with it right just some styling let me just do that quick I don't want to bore you guys more well so this is how it looks write down all that I have to do is to get the mark so in the squeeze space dot dot all I'm saying is that when you go to this result base pass marks as marks fine now again the same thing Lukas just go you say that we have an integer which is Mark's and here as soon as this result page is created we need some things which is a key which it will be a key then something that's required which is this dot marks and then all that I'm saying is super one super without key that's key which is okay it just at this case would be the pick one here we have to again pass the marks and here we have to say that we have some integer marks and I are KS and in the quiz result P is state basically we have to accept this as a constructor so which is basically this dot marks save it now we get that and I can just put it right here let's say something like congratulations you scored dollar this is not taller right dollar marks marks let's save it it will be like hey null because we don't have various let's just go back which is not good because you can't just go back right you can't just go back to and not existing quit so let's search for quiz star let's restart the application let's see how this looks right now here you can see when I click on this card we go to this quiz paste now let's say I'm giving five correct answers so marks will be 25 so okay I give a wrong answer so it'd be deaf okay ten marks print 15 marks then type okay well how about 15 marks and that's okay we could when we click on this continue I think that's something wrong with the answers which is why some answers were wrong maybe but here let's go to this quick twinspace and when somebody comes here all that want to do is we have to say navigate your chart okay off context and those replacement and we have to call our material B's route obviously but this replacement should take the person to the beginning which is the home page so what was that I guess it was home pace right home pace come on cool so when somebody clicks on this continue it will take the person to the home page now let's deal with this how do we show these marks which is also very necessary first of all does this enter had some padding no so let's just wrap the center with some padding that I'm going to say is that cut this and then the visit that I need is going to be padding with a padding of agents X dot symmetric vertical 5.0 is enough and horizontal 15.0 is enough then the child is going to be the same thing that we had this big code save it and here we have this common correlations you scored 15 marks now let's deal with this images obviously I said we have chid three different one and let me just give them some elevation so that you can see what we have right here I said 10.0 do you see did we get this elevation decent one and this image too I have wanted to give some elevation but it completely depends on you 5.0 don't think it will look good this image so I will just go with no elevation because for that I will have to again see certain things which and this just looks decent right now I think but we have a lot of things here first of all I want to create a list of a string which will talk about different images which we will show if marks are different so left of a string let's say images which will again be a list and certain images that we have our images /good dot PNG and two more let's see what are them bad dot PNG and success dot PNG okay so success is the first one good and then we have bad let's save it and then let's do right here on some more calculations which is the message to sue solar and saying is that in the whenever you in it it so in it state itself I need to do some calculations so let's first overwrite this then here I'm saying if marks is less than 40 okay let's start like this yeah if less than if marks is greater come on if marks is less than let's say 20 that means we have done bad and else if c after coding this much where I'm confusing are just some simple if-else statements if marks is less than 30 let's say that you are just good and elds which is that if marks are greater than let's say marks a greater than if 35 and that means you are the best so now that I have to do is I need a string which will be message which should be empty by default that's completely okay then I need a string which will be image which should be empty so if marks is less than 20 what do we have to do we have to say that the image is equal to images and the key is going to be to and the same applies for both of them let's just say copy paste paste one difference is that it will be 1 & 0 okay see this is the reason I'm using 35 because by default this Python or JSON has 10 questions so the total market weight 50 we can deal with that and then let's talk about messages so I'm saying the message is going to be is equal to you tried now you should try hard I think that will be good you should try hard ok 1 2 3 then a slice on which should right now here I want up to the US and it should say it you scored taller marks come on Chad you scored dollar marks and we have to just copy this thing again paste it here paste that's something like you can do better and this is the thing let's paste it let's say something like you did very well ok now we have to just switch them like we have to just keep them at their own paste positions for that but before that I've just called super dot init state that's ok let's come over here now this would be an image directly not images the image and here this would be the message directly and see these are going to be empty right now because obviously we have not done something good like we have not played the quids yet let's click on this again and here we have the quiz up and running let's triple P go then which function types of find the variable type is a correct one obviously then def is the correct one obviously not println trained is the correct one obviously type is on again the collection obviously and def is the correct one obviously type is the correct one again and def is the correct one again like how many questions are actually playing let's see Jeff is the correct one again and say it says you just okay I was playing I was using the wrong application right I never thought of it I should I quoted this earlier which I was using let me just open our application that we have coded right now which is this one so let's just stop it and restart again and wait before I do that let me first change this thing to chance so that you can actually see the desirable output in this case right now so let's do it once and for all well here we have our application let's click on python because and then we will get these questions let's play this once and for all come on we have Triple P it is a correct answer type which is okay a wrong answer def correct answer print correct answer okay okay in the type C this is wrong answer I don't know why def which is incorrect answer do we have type of as correct answer C then again def actually I would have made some mistake in a JSON file don't worry this is something you can deal with so I have lost ten marks as of now moving forward everything is correct here it says I did very well this is the trophy that I get and if I click on continue I get to start again from here so I think we have done some decent job doing this obviously this can be a lot of things that we can fix like this image and all which we will be doing for sure I mean this description and all make sure that you write them this code is going to be available you can check out a description right below and I did take a lot of time to code this complete application and make this thing possible for you guys so make sure that you appreciate this and that's it al-qaida from the next video till then keep coding keep loving keep sinning and peace [Music]
Info
Channel: Desi Programmer
Views: 57,500
Rating: undefined out of 5
Keywords: desi programmer, prince patel, desi programmer flutter, flutter by desi programmer, complete app in flutter, quiz in flutter, quiz app in flutter, flutter quiz app with timer, wuiz with timer, android quiz with timer, complete flutter tutorial, app with json in flutter, complete flutter project
Id: yHrpx4PoBzU
Channel Id: undefined
Length: 85min 13sec (5113 seconds)
Published: Sun Aug 18 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.