2013-12-15 23 views
1

嘿,我想知道如何去循环挂出浏览器的东西。飞镖 - 循环播放时挂起的浏览器

我想每秒增加一个int。

我试过使用飞镖:隔离但它会给出错误,当使用spawnFunction(); 我现在不得不使用Isolate.spawn()来痛苦。但似乎没有太多有关这方面的信息。无论是或我无法找到任何。

谢谢。

回答

1

用一个定时器,像这样:

import 'dart:html'; 
import 'dart:async'; 

void main() { 
    var div = querySelector("#my-div"); 
    int count = 0; 
    new Timer.periodic(new Duration(seconds: 1), (_) { 
    div.text = (count++).toString(); 
    }); 
} 
+0

谢谢!这固定它。 –

0

用户一个周期性的Timer对象。

Timer t = Timer.periodic(new Duration(milliseconds:1000), myCodeFluff); 

后来

int i = 0; // outside as a class attribute. 

void myCodeFluff(Timer theOriginalTimer) { 
    ++i; 
    querySelector("#myText").text = i.toString(); 
    if (i > 100) 
     theOriginalTimer.cancel(); 
} 
+1

感谢您的答复,我已导入“镖:异步”和我收到一个错误说周期性没有为类Timer定义。我必须导入其他东西吗?或者我错过了什么? –