Singleton in flutter

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this video uh we will see about the singleton classes in flutter so basically what is this singleton okay so uh if you uh might heard about the uh virtual constructors okay so that's called uh that's what uh we have to use right now and uh with the help of this singleton uh basically it's a it's a software design pattern uh that you can create only one instance and provide one global access point to that instance okay so once in once you create the instance and initiate it you can use it anywhere okay that's the idea of that uh singleton class okay so in twitter uh we are majorly using as a factory uh which is uh where we will see uh how to create an instance uh uh with the help of factory okay so let's uh see so i'm gonna make a one uh one added text field and uh let's save in a list view so you can understand it okay so let me create first of all the layout so let's have a list view so text field for the text field uh we gonna have the text controller let's name it so we just place the controller right here and we have to make one save button we have to save that instance uh to the singleton right having a row of material button one say let's say clear and one for uh one for save and one for clear so right here button okay so clear and okay so we will show the we have to provide the list right so i'm gonna create a singleton class uh in a separate file let's say data so this is the uh the basic concept of the singleton okay so just concentrate here singing you have to create name anything so uh the idea behind the singleton data if you have the large amount of data that you have to store while submitted before submitting okay so that time you can use a singleton okay so uh the use is like this create one some of the method i say internal give the global access point to the instance so let's say i'm giving a single turn of this method okay so this is basically the virtual constructor that i have created and this is the access point that we gonna use this as a factory okay so factory uh it is the meter of the uh design pattern in flutter that is uh used to return the instance of the uh particular class so here uh that is here the singleton right that we have great so our singleton class is ready so with the help of this factory uh with the help of initialization of this constructor it retards the instance of this singleton class okay right so let's create here the list a list of the uh whatever the list objects okay so you can also create uh one of the method let's reset data uh for clearing the data okay let's say this so in this way you can have the all the uh types whatever whatever we have in dart okay string in double so whatever types you can list it out here and make it reset data if you want to have some of the methods you can uh can make it here and you have to call the uh whatever the instance of the singleton class uh uh in your usable file so let's say in clear i have to call the first i have to initiate right so singleton data singleton data is equal to we have to initiate with the help of constructor so if you control click on this constructor it will go to the factory okay because we have the default constructor that is well virtual constructor uh with the singleton class okay so singleton data dot reset data because it's cleared okay so uh don't forget state because uh in this activity we have to use that state uh we have if we have to go to the another activity well you can uh that time such state is not needed okay let's set state and we have to add the uh list okay so list of objects as you see it gets and we have to add basically the text controller.text so that's it for now uh and here we have to show the list of uh objects right so string uh making the style of better understanding let's say size of 20. right okay thing we have done just making the padding of the list okay and that's here see just for the ui part let's start so how i append the center inside the row basically below the padding okay so right now the list is empty as you see so whatever i type in the edittextcontroller let's say and save it surface uh if you see uh the list uh in the signal tonight's appendage okay in this list it is appended okay so if i make something like different agile i don't so this is all about the singleton class okay so whatever you write uh just make this this set state within this current activity if you want to move uh this data to the another activity you don't have to bother about because a singleton class you can use it anywhere okay so once it is initiated uh this is used by all so clear is also working as a c so if you want to make another navigation uh just make it you will get the data okay so i hope this video will help uh for the beginners or to the flutter so thank you keep learning
Info
Channel: Kartik Gaddam
Views: 655
Rating: undefined out of 5
Keywords: singleton, singleton in flutter, use factory in flutter, factory in flutter
Id: DnMzu7hXSTk
Channel Id: undefined
Length: 8min 33sec (513 seconds)
Published: Sun Aug 21 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.