Bibek Kakati
Bibek's Blog

Follow

Bibek's Blog

Follow

Implementing Singleton Pattern In Dart - Flutter

Bibek Kakati's photo
Bibek Kakati
·Apr 19, 2021·

1 min read

Implementing Singleton Pattern In Dart - Flutter
Play this article

What is a singleton pattern?

Singleton pattern is a design pattern that allows us to use a single instance of a class everywhere.

Implementation

class ClassName {
    static ClassName _className;

    ClassName._createInstance();
    factory ClassName() {
        if (_className == null) {
            _className = ClassName._createInstance();
        }
       return _className;
    }
}

Factory constructors return an instance of the class, but it doesn't necessarily create a new instance.


Thank you for reading 🙏

If you enjoyed this article or found it helpful, give it a thumbs-up 👍

Feel free to connect 👋

Twitter | Instagram | LinkedIn

 
Share this