Skip to content

Instantly share code, notes, and snippets.

@nishtahir
Created May 19, 2020 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishtahir/f039195d769bea5b4c452dc27a9af79a to your computer and use it in GitHub Desktop.
Save nishtahir/f039195d769bea5b4c452dc27a9af79a to your computer and use it in GitHub Desktop.
void main() {
var service = Service();
service.data.get(or: 99);
}
class Service<T> {
final Loading<T> data;
Service({this.data = Loading.loading});
}
class Loading<T> {
final bool isLoading;
final T data;
const Loading(this.isLoading, this.data);
// static const Loading loading = Loading(true, null); <- doesn't compile
static const loading = Loading(true, null);
T get({T or}) {
if(isLoading) {
return or;
}
return data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment