如何使我的 CircularProgressIndicator 顺利运行(更新更平滑,而不是每秒更新,以便侧面有流动+发光?)

Bn *_*nki 5 animation flutter flutter-circularprogressindicator

所以我做了一个计时器,想知道如何添加一个“发光”,使其动画/变大一点,然后回到较小的发光。另一个问题是,当我启动计时器时,它每秒都会更新(有点跳跃而不是流动)

不知道如何继续这个,因为现在尝试谷歌几个小时但没有运气。

感谢您的帮助!

这是我的代码

  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()),
                ),
              ],
            ),
          );
Run Code Online (Sandbox Code Playgroud)

Gáb*_*bor 6

如果您需要响应值更改、跟踪某些进度,那么您可以使用AnimatedBuilder. 您提供给它的动画可确保它将根据需要更频繁地重建。

\n

但在这种特殊情况下,当您预先知道要显示多长时间,并且还知道 \xe2\x80\x93 时,除非文件复制或上传并不总是具有相同的速度 \xe2 \x80\x93 时间将以完全规则的方式流逝,您可以简单地为预定时间创建一个进度指示器。

\n
TweenAnimationBuilder<double>(\n  tween: Tween(begin: 0, end: 1),\n  duration: Duration(seconds: 25),\n  builder: (context, value, _) => CircularProgressIndicator(value: value),\n),\n
Run Code Online (Sandbox Code Playgroud)\n

这是迄今为止最简单的方法。您创建一个从零到一的补间动画,为其指定持续​​时间并使用它来构建进度指示器。

\n