convertHeicToJpegBytes method
Implementation
@override
Future<Uint8List> convertHeicToJpegBytes(Uint8List bytes) async {
// Fast-path: if it doesn't look like HEIC/HEIF, don't touch it.
if (!_looksLikeHeicOrHeif(bytes)) return bytes;
try {
// Providing a MIME type helps libraries that check blob.type.
final blob = web.Blob(
[bytes.toJS].toJS,
web.BlobPropertyBag(type: 'image/heic'),
);
final convertedBlob = await _convertHeicBlob(blob);
// Use Response API to read blob bytes (simpler than FileReader).
final response = web.Response(convertedBlob);
final arrayBuffer = await response.arrayBuffer().toDart;
return arrayBuffer.toDart.asUint8List();
} catch (e) {
// Best-effort fallback: leave bytes unchanged if conversion fails.
// ignore: avoid_print
print('[FlutterImageConversion] Web bytes conversion failed: $e');
return bytes;
}
}