【问题标题】:How do you get each timer count value? dart flutter你如何得到每个定时器的计数值?飞镖
【发布时间】:2021-09-08 04:38:57
【问题描述】:
void main() {
  final newTi = Get.put(NewTimer());
  ...
    ...
      ...: Obx((){
        return Text('${newTi.count}');
        // I'm trying to set a new timer and watch each of them. 
        // It's just 10. What should I do?
      }),
}
//
//
class NewTimer extends GetxController {
  RxInt count = 10.obs;
}
//
//
class TimerFunc extends GetxController {
  void timeRun() {
    NewTimer newTime = new NewTimer();
    Timer.periodic(Duration(seconds: 1), (t) {
      if (t.tick == 10) {
        t.cancel();
      } else {
        newTime.count--;
      }
    });
  }
}

我正在尝试设置一个新计时器并观察它们中的每一个。 才10点。我该怎么办?

.......................

【问题讨论】:

    标签: flutter timer flutter-getx


    【解决方案1】:

    吸气剂?二传手?在飞镖中。

    class NewTimer {
      double _count;
    
      NewTimer(this._count);
    
      double get count => _count;
      set count(double c) => _count = c;
    }
    
    void main() {
      print(NewTimer(2.0).count);
      print(NewTimer(3.0).count++);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多