Flutter Singleton class : How to create singleton in Dart

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome to fluty teacher in this video we will deep dive in the world of Singleton class in art I will cover everything that you need to know about it so without wasting time let's get [Music] started what exactly Singleton class is guys in object ored programming a Singleton class is a design pattern that restrict the instanciation of class to single instance in simple terms it ensures that the there is only one unique instance of class created during the entire run time of application why do we need single class the primary reason is to control and manage access to Shared resources or unique point of control in your application imagine you have a database connection or configuration manager or a login service you would want multiple instances of the services causing conflicts or resource wastage a single CL class ensures that there is only one instance of such a service throughout your application there are several ways to create Singleton class in this video I will explain three easy and most widely used ways the first way is by using Factory Constructor simply create a class and add private Constructor to it so that no one can instantiate it then create a static private field that receives the instance from our private Constructor the user final keep the field unmodified now create a factory Constructor and from here return the instance if you don't know what is Constructor or what the factory Constructor is we have several videos for this one link is there in the description go ahead and check out the link now let's create two instances of a class and print their hash code you can see both of the instances have the same hash code this proves the Singleton class now let's create Singleton class using the gator for this Al so we need to create a class with private Constructor then add static final private field in order to receive the instance from private Constructor now create a static Gator that Returns the instance Let's test our class with two different instances and you can see here as we are printing the hash code both the instances are giving the same hash code this again proves the single class one of the most easy and short way of creating Singleton class is through the static field for this also we need to create a class with private Constructor now create a non-private static field in order to receive the instance from private Constructor Let's test our class with two different instances and you can see when we print the hash code of these instances we getting the same hash code on the console so this again proves the singl turnon class that's it for this video see you guys in the next video If you really found this video helpful and knowledgeable then don't forget to like share subscribe and hit the Bell notification button to get my latest videos
Info
Channel: Flutter Teacher
Views: 749
Rating: undefined out of 5
Keywords: flutter singleton, singleton class in flutter, dart singleton, how to create singleton class in flutter, dart singleton patern, flutter singleton class, singleton design pattern, singleton, singleton class in dart, singleton pattern in flutter, how to create singleton class in dart, flutter create singleton class, singleton class flutter, creating singleton class in flutter, flutter singleton pattern, how to create singleton in dart, singleton pattern
Id: s-JFjyqYad0
Channel Id: undefined
Length: 3min 3sec (183 seconds)
Published: Wed Dec 20 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.