1

我想使用 DecodeGifAnimation 解码带有图像包的 gif ,但它需要的时间太长并且导致我的 webapp 冻结。该库似乎也没有任何异步方法。我查看了如何在 Dart 中进行异步处理,似乎我需要使用 Futures,尽管我不确定如何为我的函数创建一个。

不太确定我在做什么

void decode(Uint8List data) {
  Future anim = decodeGifAnimation(data); // but it returns Animation, not a Future!
  anim.then(prepare);
}
4

1 回答 1

7
void decode(Uint8List data) {
  new Future(() => decodeGifAnimation(data)).then(prepeare);
}

或者

Future decode(Uint8List data) {
  return new Future(() => decodeGifAnimation(data)).then(prepeare);
}

如果您想在方法返回以调用方法时进行一些异步处理,例如

decode(data).then(xxx);
于 2014-04-29T04:01:37.343 回答