#16||Flutter GetX Tutorial || Dependency Injection Get.put - Get.lazyPut - Get.putAsync - Get.create

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi my name is umar in this video i will talk about get dot put get dot lazy put get dot create and get dot put async okay now here in the main.dart file as you can see what i have done here there is a main method the main method is calling the run app method and in the run up method i am calling a widget named as my app this my app is extending the stateless widget in the build method what i have done i have created the instance of the my controller class let me uncomment this here i am creating the instance of the my controller class and to create the instance i have written git dot put my controller and it has an attribute which is called as the permanent its value is true by default it is false now what permanent will do we know that whenever the controller is unused it will be automatically removed from the memory by get x but if you made the permanent attribute true then this will be available throughout the app okay it takes one more attribute which is called as the tag okay here in the tag i am writing instance one you can provide any name as per your choice now if you provide ins tag attribute here then at the time of calling this my controller instance we can find it by using this tag name as well now how to find that portion i will discuss later on okay now here in this particular statement what i am doing i am just creating the instance of the my controller but i am not using the my controller instance anywhere in my application as you can see let me comment this as well i am not using the my instance sorry i am not using the my controller instance anywhere okay now if i do a hard refresh and if i show you the output then you will see the message get material controller has been initialized and it is printing my controller instance one has been initialized this means we are not using the my controller instance but merely writing this statement we will initialize the my controller and will allocate the memory for it okay now here let me tell you one more thing as you can see here my controller instance one has been written why because here i have used the tag property if i remove this and if i do a hard reference here then you will see that my controller has been initialized is printed this means if you are writing this statement this statement will initialize the my controller and will allocate the memory whether you are using it or not okay now here i have used the tag right if you want to find this my controller instance with the help of this tag then we can write let me uncomment this here we can write get dot find of my controller tag after that you can provide the tag name okay so we can find the my controller instance by using the tag name right now there is one more method which is called as the get dot lazy put okay now if you are using get dot lazy put then when you are writing this particular statement then this will not initialize the my controller this means memory will not be allocated for the my controller when the memory will be allocated whenever you are trying to access the my controller instance at that time only the memory will be initialized okay here let me show you by an example here i will uncomment this i will do a hard refresh go to the run tab and you will see only get material controller has been initialized but my controller is not initialized because here i have created the instance but i have not used it now whenever i will click on this particular button now clicking on the button what it will do it will use the my controller instance and whenever i will click here at that time you will see the lazy instance my controller has been created my controller has been initialized this means whenever you are trying to access the my controller instance at that time only memory will be allocated that is the difference between gate dot put and get dot lazy boot okay now here this let me discuss one more thing here it takes tag also which i discussed in my gate dot put here you can specify the tag and here it takes one more attribute which is called as the phoenix by default it is false you can make it true now what this finish will do as you can see here i have written the note phoenix is similar to permanent the difference is that the instance is discarded when is not being used but when it is use is needed again gate will recreate the instance okay that is the difference between phoenix and permanent okay now there is one more method which is called as the gate dot create okay now if you are using gate dot create then by default here permanent will be true this means this instance will be available throughout the app okay and here the a single turn will be false let me tell you one more thing in this approach that is gate dot put and get dot lazy put the is single turn is true this means only one instance will be created throughout the app but if you are using git dot create then a single turn will be false this means multiple instances will be created right that is the difference between git dot create get dot put and get dot lazy put right now there is one more method which is called as the gate dot put async okay if you want to perform some asynchronous operation then we can use get dot put async now here you can see in gate output async of type my controller now here i have written async and await because i am performing a synchronous operation and here i have specified the type okay now in the my controller what i have done i have created a method named as increment counter it is decorated as a sink because it will perform a synchronous operation here i have used the shared preferences now to use this shared preferences class in the pub spec dot ml file you can see i have taken the shared preference library okay and here i am creating the instance of the shared preference okay after that i am trying to read the value of counter from the set preference instance now by default for the first time it will not get counter as a result it will be null and whenever it will be null by default it counter will have the value as 0 and after that with that value 1 will be added okay after that it will print praised dollar counter times means it will print praised 1 times price 2 times and so on and after that here i have written preps dot second this means i am setting the value of counter to the set preference okay now let me move to the main dot dot file in the main dot dot file in the on press method i am calling the increment counter method by using get dot find of my controller okay now let me do a hard refresh let me move to the run tab let me show you the output now if i click here then you will see it is printed pressed nine times why it is printing nine times because i have already run the project and i have clicked the button that value is stored in the set preference that's why it is printing nine times okay if i click here again then you will see 10 times 11 times 12 times 13 times and so on okay this is the entire code for my controller and this is the code for main. with the notes i hope you have liked my video if you have liked my video please subscribe to my channel thank you so much for watching
Info
Channel: Ripples Code
Views: 26,636
Rating: undefined out of 5
Keywords: flutter getx tutorial, getx tutorial, state management using getx, mastering getx, getx tutorial for beginners, getx tutorial step by step, route management getx, dependency management getx, what is getx, why to use getx, advantages of getx, flutter getx dependency injection, get.put getx, get.lazyput getx, get.putasync getx, get.create getx, different ways of instantiating getx controller, best getx tutorial
Id: MVfy5LiK3rA
Channel Id: undefined
Length: 8min 48sec (528 seconds)
Published: Tue Nov 24 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.