Created
May 19, 2020 17:48
-
-
Save nishtahir/f039195d769bea5b4c452dc27a9af79a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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