mirror of
https://github.com/immich-app/immich.git
synced 2025-08-11 09:16:31 -04:00
* chore: bump dart sdk to 3.8 * chore: make build * make pigeon * chore: format files --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
41 lines
1.2 KiB
Dart
41 lines
1.2 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
|
import 'package:immich_mobile/providers/infrastructure/asset.provider.dart';
|
|
|
|
final currentAssetNotifier = AutoDisposeNotifierProvider<CurrentAssetNotifier, BaseAsset?>(CurrentAssetNotifier.new);
|
|
|
|
class CurrentAssetNotifier extends AutoDisposeNotifier<BaseAsset?> {
|
|
KeepAliveLink? _keepAliveLink;
|
|
StreamSubscription<BaseAsset?>? _assetSubscription;
|
|
|
|
@override
|
|
BaseAsset? build() => null;
|
|
|
|
void setAsset(BaseAsset asset) {
|
|
_keepAliveLink?.close();
|
|
_assetSubscription?.cancel();
|
|
state = asset;
|
|
_assetSubscription = ref.watch(assetServiceProvider).watchAsset(asset).listen((updatedAsset) {
|
|
if (updatedAsset != null) {
|
|
state = updatedAsset;
|
|
}
|
|
});
|
|
_keepAliveLink = ref.keepAlive();
|
|
}
|
|
|
|
void dispose() {
|
|
_keepAliveLink?.close();
|
|
_assetSubscription?.cancel();
|
|
}
|
|
}
|
|
|
|
final currentAssetExifProvider = FutureProvider.autoDispose((ref) {
|
|
final currentAsset = ref.watch(currentAssetNotifier);
|
|
if (currentAsset == null) {
|
|
return null;
|
|
}
|
|
return ref.watch(assetServiceProvider).getExif(currentAsset);
|
|
});
|