我想使用DecodeGifAnimation解码带有the image package的gif,但这需要太长时间并导致我的webapp冻结。该库似乎也没有任何异步方法。我查看了如何在Dart中进行异步处理,似乎我需要使用Futures,虽然我不知道如何为我的函数创建一个。
不确定我在做什么
void decode(Uint8List data) {
Future anim = decodeGifAnimation(data); // but it returns Animation, not a Future!
anim.then(prepare);
}
答案 0 :(得分: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);