Multithreading 飞镖动画问题

Multithreading 飞镖动画问题,multithreading,events,onclick,jquery-animate,dart,Multithreading,Events,Onclick,Jquery Animate,Dart,我正在使用dart动画软件包。基本上我想向左滑动一个按钮 // Register to handle 'onClick' buttonElemet.onClick.listen(onClick); void onClick(Event e) { ButtonElement button = // get the button that you want to animate int left = // get the left of the button fro

我正在使用dart动画软件包。基本上我想向左滑动一个按钮

// Register to handle 'onClick'
buttonElemet.onClick.listen(onClick);

void onClick(Event e) {        
    ButtonElement button = // get the button that you want to animate
    int left = // get the left of the button from style

    animate(button, properties: {'left':left + 100}, duration: 0);
}
当手动单击该按钮时,这将按预期工作。但我需要模拟一系列的按钮点击(基本上是为了洗牌)

因此,我通过以下方式编程调用单击事件:

for (...) {
    int numberToSlide = // select a random number to slide

    ButtonElement button = querySelector('#btn' + numberToSlide.toString());
    button.click();
}
当这种情况发生时,onClick事件中的“left”不会如预期的那样出现。经过一段相当长的调试后,我怀疑动画发生在一个线程中,当按钮被设置动画时,下一个事件进入“onClick”

关于这个问题有什么想法吗?谢谢


注意:我有一个类似的代码,但使用jqueryanimate。不过,我对jqueryanimate没有任何问题。

我会创建第二个方法

void shuffle(int left) { ... }
在onClick和simulate方法中调用它


一个好的模式:如果您有需要通过两个代码路径(一些UI,一些非UI)运行的代码,请考虑UI独立的代码。

kevmo,这与代码安排无关。。该问题是由于某些运行时行为造成的。基本上,我使用button.style.left来检索左值。但我观察到,这个值是不一致的。我观察到的是,当animate仍在更改此值时,下一次迭代将获取一个(错误的)值。我正在寻找一个解决方案来修复dart中的此类问题。Madhan:我猜这不是dart问题,而是由于动画CSS属性报告其值的行为。