【问题标题】:Flutter - The text inside the button does not changeFlutter - 按钮内的文字不会改变
【发布时间】:2021-05-27 04:41:49
【问题描述】:

我正在创建一个计时器,它有一个播放和暂停按钮,可以更改计时器内的文本,我按下“播放”,计时器开始计数,但是当我暂停时,按钮上的文本和文本定时器内部没有变化,有谁知道为什么?

AnimatedBuilder(
                  animation: controller,
                     builder: (context, child) {
                       return Padding(
                         padding: const EdgeInsets.fromLTRB(0, 10, 0, 0),
                         child: FloatingActionButton.extended(
                           backgroundColor: Colors.grey[50],
                             onPressed: () {
                               if (controller.isAnimating){
                                 controller.stop();
                                 }
                               else {
                                 controller.reverse(
                                     from: controller.value == 0.0
                                         ? 1.0
                                         : controller.value);
                               }
                             },
                             icon: Icon(controller.isAnimating
                                 ? Icons.pause
                                 : Icons.play_arrow),
                             label: Text(
                                 controller.isAnimating ? "Pause" : "Play")),
                       );
                     }),

Normal

Couting

Paused

【问题讨论】:

    标签: android ios flutter dart mobile


    【解决方案1】:

    尝试将controller.stop(); 调用为setState

    像这样:

    setState(() {
      controller.stop();
    });
    

    【讨论】:

      猜你喜欢
      • 2012-05-02
      • 1970-01-01
      • 2015-12-16
      • 2020-01-20
      • 1970-01-01
      • 2019-10-05
      • 2020-06-06
      • 2018-07-17
      • 1970-01-01
      相关资源
      最近更新 更多