Skip to content

Instantly share code, notes, and snippets.

@yungwarlock
Last active June 26, 2023 14:24
Show Gist options
  • Save yungwarlock/593f2ee5048ea5989ff4b916239da353 to your computer and use it in GitHub Desktop.
Save yungwarlock/593f2ee5048ea5989ff4b916239da353 to your computer and use it in GitHub Desktop.
Dart Timer
import 'dart:async';
void main() {
int countDown = 60;
bool shouldShowResend = false;
Timer.periodic(const Duration(seconds: 1), (t) {
print(formatTime(countDown));
print(shouldShowResend);
});
Timer.periodic(const Duration(seconds: 1), (t) {
if(countDown == 0) {
shouldShowResend = true;
return;
}
countDown--;
});
}
String formatTime(int period) {
var minutes = (period ~/ 60).toString().padLeft(2, "0");
var seconds = (period % 60).toString().padLeft(2, "0");
return "$minutes:$seconds";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment