Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The argument type 'Object?' can't be assigned to the parameter type 'FutureOr<Uint8List>?'

How to solve this error? Error message: The argument type ‘Object?’ can’t be assigned to the parameter type ‘FutureOr<Uint8List>?’.

enter image description here

My code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

}

  Future<Uint8List> _getBlobData(html.Blob blob) {
    final completer = Completer<Uint8List>();
    final reader = html.FileReader();
    reader.readAsArrayBuffer(blob);
    reader.onLoad.listen((_) => completer.complete(reader.result));
    return completer.future;
  }

>Solution :

FileReader.result returns an Object? because it could return a Uint8List, a String, or null. If you can guarantee that reader.result is a Uint8List, just perform a cast:

reader.onLoad.listen((_) => completer.complete(reader.result! as Uint8List));

Otherwise you should check the type of reader.result first. For example:

reader.onLoad.listen((_) {
  var result = reader.result;
  if (result is Uint8List) {
    completer.complete(result);
  } else {
    completer.completeError(
      Exception('Unexpected result type: ${result.runtimeType}'));
  }
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading