mirror of
https://github.com/immich-app/immich.git
synced 2026-08-01 00:21:10 -07:00
* chore(mobile): Apply stricter linting rules for formatting * Formatting fixes
50 lines
1.5 KiB
Dart
50 lines
1.5 KiB
Dart
part of 'image_request.dart';
|
|
|
|
class RemoteImageRequest extends ImageRequest {
|
|
final String uri;
|
|
|
|
RemoteImageRequest({required this.uri});
|
|
|
|
@override
|
|
Future<ImageInfo?> load(ImageDecoderCallback decode, {double scale = 1.0}) async {
|
|
if (_isCancelled) {
|
|
return null;
|
|
}
|
|
|
|
final info = await remoteImageApi.requestImage(uri, requestId: requestId, preferEncoded: false);
|
|
// Android falls back to encoded data if native decoding fails, so check for both shapes of the response.
|
|
final frame = switch (info) {
|
|
{'pointer': final int pointer, 'length': final int length} => await _fromEncodedPlatformImage(pointer, length),
|
|
{
|
|
'pointer': final int pointer,
|
|
'width': final int width,
|
|
'height': final int height,
|
|
'rowBytes': final int rowBytes,
|
|
} =>
|
|
await _fromDecodedPlatformImage(pointer, width, height, rowBytes),
|
|
_ => null,
|
|
};
|
|
return frame == null ? null : ImageInfo(image: frame.image, scale: scale);
|
|
}
|
|
|
|
@override
|
|
Future<ui.Codec?> loadCodec() async {
|
|
if (_isCancelled) {
|
|
return null;
|
|
}
|
|
|
|
final info = await remoteImageApi.requestImage(uri, requestId: requestId, preferEncoded: true);
|
|
if (info == null) {
|
|
return null;
|
|
}
|
|
|
|
final (codec, _) = await _codecFromEncodedPlatformImage(info['pointer']!, info['length']!) ?? (null, null);
|
|
return codec;
|
|
}
|
|
|
|
@override
|
|
Future<void> _onCancelled() {
|
|
return remoteImageApi.cancelRequest(requestId);
|
|
}
|
|
}
|