2025-08-20 15:36:44 -04:00
|
|
|
part of 'image_request.dart';
|
|
|
|
|
|
|
|
|
|
class RemoteImageRequest extends ImageRequest {
|
|
|
|
|
final String uri;
|
|
|
|
|
|
2026-08-10 21:14:23 +06:00
|
|
|
/// Physical size to decode, or null for the source size.
|
|
|
|
|
final ui.Size? decodeSize;
|
|
|
|
|
|
|
|
|
|
RemoteImageRequest({required this.uri, this.decodeSize});
|
2025-08-20 15:36:44 -04:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<ImageInfo?> load(ImageDecoderCallback decode, {double scale = 1.0}) async {
|
|
|
|
|
if (_isCancelled) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 21:14:23 +06:00
|
|
|
final info = await remoteImageApi.requestImage(
|
|
|
|
|
uri,
|
|
|
|
|
requestId: requestId,
|
|
|
|
|
preferEncoded: false,
|
|
|
|
|
width: decodeSize?.width.ceil(),
|
|
|
|
|
height: decodeSize?.height.ceil(),
|
|
|
|
|
);
|
2026-07-07 03:16:09 +06:00
|
|
|
// Android falls back to encoded data if native decoding fails, so check for both shapes of the response.
|
2026-01-24 14:34:29 -05:00
|
|
|
final frame = switch (info) {
|
2026-08-10 21:14:23 +06:00
|
|
|
{'pointer': final int pointer, 'length': final int length} => await _fromEncodedPlatformImage(
|
|
|
|
|
pointer,
|
|
|
|
|
length,
|
|
|
|
|
decodeSize: decodeSize,
|
|
|
|
|
),
|
2026-07-30 01:56:46 -07:00
|
|
|
{
|
|
|
|
|
'pointer': final int pointer,
|
|
|
|
|
'width': final int width,
|
|
|
|
|
'height': final int height,
|
|
|
|
|
'rowBytes': final int rowBytes,
|
|
|
|
|
} =>
|
2026-01-24 14:34:29 -05:00
|
|
|
await _fromDecodedPlatformImage(pointer, width, height, rowBytes),
|
|
|
|
|
_ => null,
|
|
|
|
|
};
|
|
|
|
|
return frame == null ? null : ImageInfo(image: frame.image, scale: scale);
|
2025-08-20 15:36:44 -04:00
|
|
|
}
|
|
|
|
|
|
2026-02-28 17:43:58 +01:00
|
|
|
@override
|
|
|
|
|
Future<ui.Codec?> loadCodec() async {
|
|
|
|
|
if (_isCancelled) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 21:14:23 +06:00
|
|
|
final info = await remoteImageApi.requestImage(
|
|
|
|
|
uri,
|
|
|
|
|
requestId: requestId,
|
|
|
|
|
preferEncoded: true,
|
|
|
|
|
width: null,
|
|
|
|
|
height: null,
|
|
|
|
|
);
|
2026-05-12 00:47:24 +07:00
|
|
|
if (info == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2026-02-28 17:43:58 +01:00
|
|
|
|
|
|
|
|
final (codec, _) = await _codecFromEncodedPlatformImage(info['pointer']!, info['length']!) ?? (null, null);
|
|
|
|
|
return codec;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-20 15:36:44 -04:00
|
|
|
@override
|
2026-01-24 14:34:29 -05:00
|
|
|
Future<void> _onCancelled() {
|
|
|
|
|
return remoteImageApi.cancelRequest(requestId);
|
2025-08-20 15:36:44 -04:00
|
|
|
}
|
|
|
|
|
}
|