Skip to content

Instantly share code, notes, and snippets.

@adam-singer
Forked from atebitftw/Dart_Singleton_Maybe
Created April 27, 2012 00:32
Show Gist options
  • Save adam-singer/2504606 to your computer and use it in GitHub Desktop.
Save adam-singer/2504606 to your computer and use it in GitHub Desktop.
Dart Singleton?
class MyClass{
static MyClass _ref;
static MyClass get context() => _ref == null ? new MyClass() : _ref;
factory MyClass(){
if (_ref != null) return _ref;
_ref = new MyClass._internal();
return _ref;
}
MyClass._internal(){}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment