圆形倒数计时器颤振

时间:2021-05-15 13:05:21

标签: flutter dart

时间到了,我怎样才能从倒计时中去掉“00”?

Widget _buildTimer() {
    return CircularCountDownTimer(
      fillColor: Colors.red,
      color: Colors.white,
      backgroundColor: null,
      duration: _data[_currentIndex].duration,
      controller: _controller,
      width: MediaQuery.of(context).size.width / 4,
      height: MediaQuery.of(context).size.height / 4,
      strokeWidth: 10.0,
      strokeCap: StrokeCap.round,
      textStyle: TextStyle(
          fontSize: 33.0, color: Colors.black, fontWeight: FontWeight.bold),
      textFormat: CountdownTextFormat.SS,
      isReverse: true,
      isReverseAnimation: true,
      isTimerTextShown: true,
      autoStart: true,
    );
  }

时间到了就是这个样子

enter image description here

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

我假设您正在使用这个 https://pub.dev/packages/circular_countdown_timer

在这种情况下,您需要有一个变量来控制文本可见性的状态。然后您可以在 onComplete 回调中更改此设置。

  bool isTimerShown = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CircularCountDownTimer(
        fillColor: Colors.red,
        backgroundColor: null,
        duration: 3,
        controller: CountDownController(),
        width: MediaQuery
            .of(context)
            .size
            .width / 4,
        height: MediaQuery
            .of(context)
            .size
            .height / 4,
        strokeWidth: 10.0,
        strokeCap: StrokeCap.round,
        textStyle: TextStyle(
          fontSize: 33.0,
          color: Colors.black,
          fontWeight: FontWeight.bold,
        ),
        textFormat: CountdownTextFormat.SS,
        isReverse: true,
        isReverseAnimation: true,
        isTimerTextShown: isTimerShown,
        autoStart: true,
        ringColor: Colors.white,
        onComplete: () =>
            setState(() {
              isTimerShown = false;
            }),
      ),
    );
  }