main() {
//传递给Future构造函数的函数参数会立即开始执行,但是可能非常耗时,但不阻塞接下来的代码执行
var future = Future(() {
print('hello world');
});
print('this run here1');
//Future.then也不阻塞它后面的代码执行
future.then((value) => print(value));
print('this run here2');
}
实测结果(可能每次都不一样,具体取决于要执行的语句和机器)
[Running] dart "c:\Users\root\Desktop\flutter\myshop\test.dart"
this run here1
this run here2
hello world
null
网友评论