0

这个错误是什么意思以及如何解决?

错误:

Animation? decodeImage
The argument type 'Image?' can't be assigned to the parameter type 'Image'

飞镖代码:

import 'dart:io';
import 'package:image/image.dart';

void main(){

  final image = 'asset/test.webp';

  final bytes = File(image).readAsBytesSync(); // type List<int>
  final decodeImage = decodeWebPAnimation(bytes); // type Animation

  var obj = WebPEncoder(); 

  obj.addFrame(decodeImage?[0]); // gives error

}

有哪些修复方法?

4

2 回答 2

0

尝试使其非空再见添加bang( !) 像这样:

  obj.addFrame(decodeImage?[0]!);
于 2022-02-24T17:41:29.710 回答
0

我通过使用修复它as [type]

obj.addFrame(decodeImage?[0] as Image);

参考:https ://stackoverflow.com/a/68969699/9308731

于 2022-02-24T18:01:15.830 回答