Skip to content

Instantly share code, notes, and snippets.

@atebitftw
Created April 26, 2012 20:54
Show Gist options
  • Save atebitftw/2503120 to your computer and use it in GitHub Desktop.
Save atebitftw/2503120 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(){}
}
@adam-singer
Copy link

Nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment