1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-03-01 15:11:21 +01:00
immich/mobile/lib/providers/asset_viewer/asset_stack.provider.dart
Alex 47203d2760
refactor(mobile): asset stack provider (#16100)
* refactor(mobile): asset stack provider

* remove file from ignore list
2025-02-14 13:23:14 -06:00

44 lines
1.1 KiB
Dart

import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/entities/asset.entity.dart';
import 'package:immich_mobile/services/asset.service.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'asset_stack.provider.g.dart';
class AssetStackNotifier extends StateNotifier<List<Asset>> {
final AssetService assetService;
final String _stackId;
AssetStackNotifier(this.assetService, this._stackId) : super([]) {
_fetchStack(_stackId);
}
void _fetchStack(String stackId) async {
if (!mounted) {
return;
}
final stack = await assetService.getStackAssets(stackId);
if (stack.isNotEmpty) {
state = stack;
}
}
void removeChild(int index) {
if (index < state.length) {
state.removeAt(index);
state = List<Asset>.from(state);
}
}
}
final assetStackStateProvider = StateNotifierProvider.autoDispose
.family<AssetStackNotifier, List<Asset>, String>(
(ref, stackId) =>
AssetStackNotifier(ref.watch(assetServiceProvider), stackId),
);
@riverpod
int assetStackIndex(AssetStackIndexRef ref, Asset asset) {
return -1;
}