Skip to content

Instantly share code, notes, and snippets.

@yjbanov
Created March 23, 2018 01:58
Show Gist options
  • Save yjbanov/7fb970f0d50ef5a78d6aef4db5c6ad07 to your computer and use it in GitHub Desktop.
Save yjbanov/7fb970f0d50ef5a78d6aef4db5c6ad07 to your computer and use it in GitHub Desktop.
The Hundreds widget
class Hundreds extends StatefulWidget {
Hundreds(this.stopwatch);
final Stopwatch stopwatch;
HundredsState createState() => new HundredsState(stopwatch);
}
class HundredsState extends State<Hundreds> {
final Stopwatch stopwatch;
int hundreds = 0;
HundredsState(this.stopwatch);
@override
void initState() {
timerListeners.add(onTick);
super.initState();
}
void onTick(ElapsedTime elapsed) {
if (elapsed.hundreds != hundreds) {
setState(() {
hundreds = elapsed.hundreds;
});
}
}
@override
Widget build(BuildContext context) {
String minutesStr = (hundreds % 100).toString().padLeft(2, '0');
return new Text(minutesStr, style: timerTextStyle);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment