所以我做了一个计时器,想知道如何添加一个“发光”,使动画/稍微变大,然后再变小。另一个问题是,当我启动计时器时,它每秒更新一次(跳跃而不是流动)
不知道如何继续这样做,因为现在尝试谷歌几个小时没有运气。
感谢您的帮助!
这是我的代码
var maxSeconds = 900;
late int seconds = maxSeconds;
Timer? timer;
void resetTimer() {
setState(() => seconds = maxSeconds);
timer = null;
}
void startTimer({bool reset = true}) {
if (reset) {
resetTimer();
}
timer = Timer.periodic(Duration(seconds: 1), (_) {
if (!mounted) // Putting this line of code with return under, fixed my issue i been having about mounted
return;
else if (seconds > 0) {
setState(() => seconds--);
} else {
stopTimer(reset: false);
}
});
}
Widget buildTimer() => SizedBox(
width: 200,
height: 200,
child: Stack(
fit: StackFit.expand,
children: [
CircularProgressIndicator(
value: seconds / maxSeconds,
valueColor: AlwaysStoppedAnimation(Colors.white),
strokeWidth: 12,
backgroundColor: Colors.greenAccent,
),
GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
if (timer == null) {
HapticFeedback.heavyImpact();
} else {
}
},
child: Center(child: buildTime()),
),
],
),
);