minor change

This commit is contained in:
Thibault Deckers 2021-07-16 17:53:40 +09:00
parent 2e53352f59
commit 6c3ec82dba

View file

@ -157,7 +157,8 @@ class _FeedbackMessage extends StatefulWidget {
} }
class _FeedbackMessageState extends State<_FeedbackMessage> { class _FeedbackMessageState extends State<_FeedbackMessage> {
late int _totalSecs, _elapsedSecs = 0; double _percent = 0;
late int _remainingSecs;
Timer? _timer; Timer? _timer;
@override @override
@ -165,10 +166,11 @@ class _FeedbackMessageState extends State<_FeedbackMessage> {
super.initState(); super.initState();
final duration = widget.duration; final duration = widget.duration;
if (duration != null) { if (duration != null) {
_totalSecs = duration.inSeconds; _remainingSecs = duration.inSeconds;
_timer = Timer.periodic(const Duration(seconds: 1), (_) { _timer = Timer.periodic(const Duration(seconds: 1), (_) {
setState(() => _elapsedSecs++); setState(() => _remainingSecs--);
}); });
WidgetsBinding.instance!.addPostFrameCallback((_) => setState(() => _percent = 1.0));
} }
} }
@ -189,14 +191,14 @@ class _FeedbackMessageState extends State<_FeedbackMessage> {
Expanded(child: text), Expanded(child: text),
const SizedBox(width: 16), const SizedBox(width: 16),
CircularPercentIndicator( CircularPercentIndicator(
percent: (_elapsedSecs.toDouble() / (_totalSecs - 1)).clamp(0.0, 1.0), percent: _percent,
lineWidth: 2, lineWidth: 2,
radius: 32, radius: 32,
backgroundColor: Theme.of(context).accentColor, backgroundColor: Theme.of(context).accentColor,
progressColor: Colors.grey, progressColor: Colors.grey,
animation: true, animation: true,
animationDuration: 1000, animationDuration: duration.inMilliseconds,
center: Text('${_totalSecs - _elapsedSecs}'), center: Text('$_remainingSecs'),
animateFromLastPercent: true, animateFromLastPercent: true,
reverse: true, reverse: true,
), ),