Issue
How to solve this error? Error message: The argument type 'Object?' can't be assigned to the parameter type 'FutureOr<Uint8List>?'.
My code
}
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}'));
}
});
Answered By - jamesdlin

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.