2025-06-16 20:37:45 +05:30
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
|
import 'package:flutter/rendering.dart';
|
2025-08-13 03:05:27 -04:00
|
|
|
import 'package:immich_mobile/infrastructure/repositories/asset_media.repository.dart';
|
|
|
|
|
import 'package:immich_mobile/presentation/widgets/images/image_provider.dart';
|
|
|
|
|
import 'package:immich_mobile/presentation/widgets/images/one_frame_multi_image_stream_completer.dart';
|
2025-06-16 20:37:45 +05:30
|
|
|
|
2025-08-13 03:05:27 -04:00
|
|
|
class ThumbHashProvider extends ImageProvider<ThumbHashProvider> with CancellableImageProviderMixin {
|
2025-06-16 20:37:45 +05:30
|
|
|
final String thumbHash;
|
|
|
|
|
|
2025-08-13 03:05:27 -04:00
|
|
|
ThumbHashProvider({required this.thumbHash});
|
2025-06-16 20:37:45 +05:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<ThumbHashProvider> obtainKey(ImageConfiguration configuration) {
|
|
|
|
|
return SynchronousFuture(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
2025-07-29 00:34:03 +05:30
|
|
|
ImageStreamCompleter loadImage(ThumbHashProvider key, ImageDecoderCallback decode) {
|
2025-08-13 03:05:27 -04:00
|
|
|
final completer = OneFramePlaceholderImageStreamCompleter(_loadCodec(key, decode));
|
|
|
|
|
completer.addOnLastListenerRemovedCallback(cancel);
|
|
|
|
|
return completer;
|
2025-06-16 20:37:45 +05:30
|
|
|
}
|
|
|
|
|
|
2025-08-13 03:05:27 -04:00
|
|
|
Stream<ImageInfo> _loadCodec(ThumbHashProvider key, ImageDecoderCallback decode) async* {
|
|
|
|
|
final request = this.request = ThumbhashImageRequest(thumbhash: thumbHash);
|
|
|
|
|
try {
|
|
|
|
|
final image = await request.load(decode);
|
|
|
|
|
if (image != null) {
|
|
|
|
|
yield image;
|
|
|
|
|
}
|
|
|
|
|
} finally {
|
|
|
|
|
this.request = null;
|
|
|
|
|
}
|
2025-06-16 20:37:45 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
bool operator ==(Object other) {
|
|
|
|
|
if (identical(this, other)) return true;
|
|
|
|
|
if (other is ThumbHashProvider) {
|
|
|
|
|
return thumbHash == other.thumbHash;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
int get hashCode => thumbHash.hashCode;
|
|
|
|
|
}
|