java - Android:Flutter SDK 中的 CountDownTimer 等效项

标签 java android flutter dart

我在 Android Studio 中有一个自定义 View,它使用自定义动画每 x 毫秒更新一次。我现在正在尝试在 Dart 中实现这种行为。这就是Android Java中动画的实现方式。 (仅代表动画逻辑,不执行其他任何操作)

public class ItemAnim extends CountDownTimer {

    public ItemAnim(long millisInFuture, long countdownInterval){
       super(millisInFuture, countdownInterval);
    }

    @Override
    public void onTick(long millisUntilFinished) {    
        // do anim stuff like setting a rotation angle variable etc...
        // listener.animate(...) code
    }
}

我现在正在 Dart/Flutter SDK 中寻找一个非常相似的类。

即每 countdownInterval 毫秒调用 onTick(millisUntilFinished) 的类

最佳答案

您可以使用

Timer.periodic(duration, callback)

它将重复任务直到取消

示例

var timer = Timer.periodic(Duration(seconds: 1), (Timer t){
      //your code here
    });

取消使用

timer.cancel();

关于java - Android:Flutter SDK 中的 CountDownTimer 等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58017612/

相关文章:

java - 在多个线程中洗牌数组

java - 使用 DatagramSockets 的迭代 DNS 客户端

android - 如何修复 HelloCardboard 示例的 NDK 构建错误

java.lang.NoSuchMethodError : No interface method onTransitionToIdle()V 错误

android - 如何在flutter中显示本地html?

flutter - 如何使用 statelessWidget 从 Api 获取数据

java - 当光标放在图表上时显示图表的值

java - JLine 3 - 使提示始终位于底部

android - 在 Phonegap 3/Cordova 3 中检索用户 sim 号码

flutter - 在 Flutter 中过滤和排序来自 Hive box 的记录