FlutterCountdownTimer
FlutterCountdownTimer copied to clipboard
animating milliseconds
any plans to show milliseconds counting down? they move fast but would be nice to have it so it's like a super precise stopwatch. thanks
4.0.2 has been released to support this feature.The implementation can be found in the example.
class _CountdownTimerPageState extends State<CountdownTimerPage>
with SingleTickerProviderStateMixin {
late CountdownTimerController controller;
int endTime = DateTime.now().millisecondsSinceEpoch +
Duration(seconds: 30).inMilliseconds;
@override
void initState() {
super.initState();
controller =
CountdownTimerController(endTime: endTime, onEnd: onEnd, vsync: this);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
CountdownTimer(
controller: controller,
widgetBuilder: (BuildContext context, CurrentRemainingTime? time) {
if (time == null) {
return Text('Game over');
}
List<Widget> list = [];
if (time.sec != null) {
list.add(Row(
children: <Widget>[
Icon(Icons.sentiment_very_satisfied),
Text(time.sec.toString()),
],
));
}
if (time.milliseconds != null) {
list.add(Row(
children: <Widget>[
Icon(Icons.sentiment_very_satisfied),
AnimatedBuilder(
animation: time.milliseconds!,
builder: (context, child) {
return Text("${(time.milliseconds!.value * 1000).toInt()}");
},
)
],
));
}
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: list,
);
},
),
],
),
);
}
}
awesome thanks!