Skip to content

Instantly share code, notes, and snippets.

View komapeb's full-sized avatar

Kristiyan Mitev komapeb

View GitHub Profile
@komapeb
komapeb / singleton.dart
Created June 3, 2019 15:41
Simple Singleton pattern implementation in Dart, without using the ugly Singleton.instance or Singleton.getInstance(). Just Singleton() returns the singleton instance. Beautiful.
// Singleton logic
class Singleton {
// This makes sure Singleton() always returns the same instance
static final Singleton _instance = Singleton._();
Singleton._();
factory Singleton() {
return _instance;
}
// define any props, methods you want