void test() async {
print('外部代码1');
// 创建Port 端口
ReceivePort receivePort = ReceivePort();
// 创建Isolate
Isolate iso = await Isolate.spawn(oneWayEntryPoint, receivePort.sendPort);
receivePort.listen((message) {
print('端口回来的数据a是$message');
receivePort.close();
iso.kill(priority: Isolate.immediate); //使用完毕之后释放
iso = null;
print('2333');
});
}
static oneWayEntryPoint(SendPort sendPort) async {
// 处理耗时任务
// ........
sendPort.send(1000);
}
Flutter 多线程调用
最新推荐文章于 2025-05-19 16:28:34 发布