Files
immich/mobile/lib/presentation/widgets/images/thumb_hash_provider.dart
T
Santo Shakil a29153e90e fix(mobile): face thumbnail stuck blank after renaming a person (#30769)
* fix(mobile): face thumbnail stuck blank after renaming a person

* flatten the codec error guard and rework the tests around framework driven reuse

* trim the image provider tests and note the per load state rule

* keep two small image provider tests: the renamed face and a late failure of a cancelled load

* clearer image provider tests: return the created completer, comment the steps, drop the unused listener, rename to thumbWithChecksum

* use the provider constructor with a lint ignore in the cache key test
2026-09-30 00:43:21 +06:00

45 lines
1.4 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:immich_mobile/infrastructure/loaders/image_request.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';
class ThumbHashProvider extends ImageProvider<ThumbHashProvider> {
final String thumbHash;
const ThumbHashProvider({required this.thumbHash});
@override
Future<ThumbHashProvider> obtainKey(ImageConfiguration configuration) {
return SynchronousFuture(this);
}
@override
ImageStreamCompleter loadImage(ThumbHashProvider key, ImageDecoderCallback decode) {
final loader = ImageLoader(key);
return OneFramePlaceholderImageStreamCompleter(
_loadCodec(loader, key, decode),
onLastListenerRemoved: loader.cancel,
);
}
Stream<ImageInfo> _loadCodec(ImageLoader loader, ThumbHashProvider key, ImageDecoderCallback decode) {
final request = loader.request = ThumbhashImageRequest(thumbhash: key.thumbHash);
return loader.loadRequest(request, decode, isFinal: true);
}
@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;
}