Last active
June 27, 2019 07:55
-
-
Save claireliu14/55229e8e2bb33644e0e132e9ef294521 to your computer and use it in GitHub Desktop.
Sample of Future
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
import 'dart:async'; | |
void main() { | |
getAJoke().then((value) { | |
print(value); | |
}) | |
.whenComplete(() { | |
print('Complete'); | |
}) | |
.catchError((error) { | |
print('Error'); | |
}); | |
} | |
Future<String> getAJoke() { | |
return new Future<String>.delayed( | |
const Duration(seconds: 5), () { | |
return "This is a joke"; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment