0

What is the meaning of this error and how to solve it?

Error:

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

Dart Code:

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

}

What are the methods to fix it?

CrackerKSR
  • 1,380
  • 1
  • 11
  • 29

2 Answers2

0

Try making it non-null bye adding the bang (!) like so:

  obj.addFrame(decodeImage?[0]!);
Josteve
  • 11,459
  • 1
  • 23
  • 35
0

I fixed it by using as [type]

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

Ref: https://stackoverflow.com/a/68969699/9308731

CrackerKSR
  • 1,380
  • 1
  • 11
  • 29