Skip to content

Instantly share code, notes, and snippets.

@ramansah
Last active December 24, 2018 06:38
Show Gist options
  • Save ramansah/a37cfc7d575f80dcff1581569dece942 to your computer and use it in GitHub Desktop.
Save ramansah/a37cfc7d575f80dcff1581569dece942 to your computer and use it in GitHub Desktop.
class TimerAppState extends State<TimerApp> {
static const duration = const Duration(seconds:1);
int secondsPassed = 0;
bool isActive = false;
Timer timer;
void handleTick() {
if (isActive) {
setState(() {
secondsPassed = secondsPassed + 1;
});
}
}
@override
void initState() {
timer = Timer.periodic(duration, (Timer t) {
handleTick();
});
super.initState();
}
@override
Widget build(BuildContext context) {
int seconds = secondsPassed % 60;
int minutes = secondsPassed ~/ 60;
int hours = secondsPassed ~/ (60*60);
return MaterialApp(...)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment