Skip to content

Instantly share code, notes, and snippets.

@felipecarvalho
Created March 15, 2019 21:21
Show Gist options
  • Select an option

  • Save felipecarvalho/2ca102102a010ff0b6162d896cadaee3 to your computer and use it in GitHub Desktop.

Select an option

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
// 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