문제

I want to decode a gif with the image package using DecodeGifAnimation, but it takes too long and causes my webapp to freeze. The library also doesn't seem to have any async methods. I looked up how to do asynchronous processing in Dart, and it seems that I need to use Futures, although I'm not sure how to create one for my function.

Not really sure what I'm doing

void decode(Uint8List data) {
  Future anim = decodeGifAnimation(data); // but it returns Animation, not a Future!
  anim.then(prepare);
}
도움이 되었습니까?

해결책

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

or

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

if you want to do some async processing when the method returns to call the method like

decode(data).then(xxx);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top