Created
March 15, 2019 21:21
-
-
Save felipecarvalho/2ca102102a010ff0b6162d896cadaee3 to your computer and use it in GitHub Desktop.
Using FOR structure with ASYNC and FUTURE to create a timer with response in Dart language
This file contains hidden or 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
| // Created by Felipe Carvalho [http://github.com/felipecarvalho] | |
| // You can play with this code on DartPad [https://dartpad.dartlang.org/2ca102102a010ff0b6162d896cadaee3] | |
| void main() async { | |
| int start = 10; | |
| int timeout = 1; | |
| print("The clock's alarm is running..."); | |
| for (int i = start; i >= timeout; i--) { | |
| await Future.delayed(Duration(seconds: 1), () { | |
| if (i >= timeout) print('${i} second${i != 1 ? 's' : ''} to wakeup'); | |
| if (i == timeout) print('TRIIIIIIIIIIIM!'); | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment