promiseToFuture<T> 函数

Future<T> promiseToFuture<T>(
  1. Object jsPromise
)

将 JavaScript Promise 转换为 Dart Future

@JS()
external Promise<num> get threePromise; // Resolves to 3

void main() async {
  final Future<num> threeFuture = promiseToFuture(threePromise);

  final three = await threeFuture; // == 3
}

实现

external Future<T> promiseToFuture<T>(Object jsPromise);