CrackerKSR
CrackerKSR

Reputation: 1917

Dart: The argument type 'Image?' can't be assigned to the parameter type 'Image'

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?

Upvotes: 0

Views: 1817

Answers (2)

CrackerKSR
CrackerKSR

Reputation: 1917

I fixed it by using as [type]

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

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

Upvotes: 0

Josteve Adekanbi
Josteve Adekanbi

Reputation: 12673

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

  obj.addFrame(decodeImage?[0]!);

Upvotes: 0

Related Questions