Created
March 23, 2018 01:58
-
-
Save yjbanov/7fb970f0d50ef5a78d6aef4db5c6ad07 to your computer and use it in GitHub Desktop.
The Hundreds widget
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 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