Last active
December 24, 2018 06:38
-
-
Save ramansah/a37cfc7d575f80dcff1581569dece942 to your computer and use it in GitHub Desktop.
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
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