- Upgrade flutter_riverpod to 3.1.0, riverpod_annotation to 4.0.0 - Upgrade freezed to 3.2.3, freezed_annotation to 3.1.0 - Migrate freezed classes to use sealed keyword (freezed 3.x) - Update provider naming (*NotifierProvider → *Provider) - Add legacy.dart import for StateNotifierProvider compatibility - Fix valueOrNull → value for AsyncValue - Remove unused imports and fields - Add sync from Authentik button to users/groups pages - Suppress invalid_annotation_target warning in analysis_options 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
92 lines
2.9 KiB
Dart
92 lines
2.9 KiB
Dart
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
import 'package:tatlock_ui/features/control_room/containers/data/repositories/container_repository_impl.dart';
|
|
import 'package:tatlock_ui/features/control_room/containers/domain/entities/container.dart';
|
|
import 'package:tatlock_ui/features/control_room/stacks/presentation/providers/stacks_provider.dart';
|
|
|
|
part 'containers_provider.g.dart';
|
|
|
|
/// Provides all containers.
|
|
@riverpod
|
|
Future<List<Container>> allContainers(Ref ref) async {
|
|
final repository = ref.watch(containerRepositoryProvider);
|
|
return repository.getContainers();
|
|
}
|
|
|
|
/// Provides containers filtered by the selected stack.
|
|
@riverpod
|
|
Future<List<Container>> containers(Ref ref) async {
|
|
final repository = ref.watch(containerRepositoryProvider);
|
|
final selectedStack = ref.watch(selectedStackProvider);
|
|
|
|
if (selectedStack == null) {
|
|
return repository.getContainers();
|
|
}
|
|
|
|
return repository.getContainersByStack(selectedStack);
|
|
}
|
|
|
|
/// Provides a single container by ID.
|
|
@riverpod
|
|
Future<Container> container(Ref ref, String id) async {
|
|
final repository = ref.watch(containerRepositoryProvider);
|
|
return repository.getContainer(id);
|
|
}
|
|
|
|
/// Controller for container actions.
|
|
@riverpod
|
|
class ContainerActions extends _$ContainerActions {
|
|
@override
|
|
AsyncValue<void> build() => const AsyncValue.data(null);
|
|
|
|
Future<void> start(String id) async {
|
|
state = const AsyncValue.loading();
|
|
state = await AsyncValue.guard(() async {
|
|
final repository = ref.read(containerRepositoryProvider);
|
|
await repository.startContainer(id);
|
|
ref.invalidate(allContainersProvider);
|
|
ref.invalidate(containersProvider);
|
|
});
|
|
}
|
|
|
|
Future<void> stop(String id) async {
|
|
state = const AsyncValue.loading();
|
|
state = await AsyncValue.guard(() async {
|
|
final repository = ref.read(containerRepositoryProvider);
|
|
await repository.stopContainer(id);
|
|
ref.invalidate(allContainersProvider);
|
|
ref.invalidate(containersProvider);
|
|
});
|
|
}
|
|
|
|
Future<void> restart(String id) async {
|
|
state = const AsyncValue.loading();
|
|
state = await AsyncValue.guard(() async {
|
|
final repository = ref.read(containerRepositoryProvider);
|
|
await repository.restartContainer(id);
|
|
ref.invalidate(allContainersProvider);
|
|
ref.invalidate(containersProvider);
|
|
});
|
|
}
|
|
|
|
Future<void> remove(String id, {bool force = false}) async {
|
|
state = const AsyncValue.loading();
|
|
state = await AsyncValue.guard(() async {
|
|
final repository = ref.read(containerRepositoryProvider);
|
|
await repository.removeContainer(id, force: force);
|
|
ref.invalidate(allContainersProvider);
|
|
ref.invalidate(containersProvider);
|
|
});
|
|
}
|
|
}
|
|
|
|
/// Container logs provider.
|
|
@riverpod
|
|
Future<String> containerLogs(
|
|
Ref ref,
|
|
String id, {
|
|
int? tail = 100,
|
|
}) async {
|
|
final repository = ref.watch(containerRepositoryProvider);
|
|
return repository.getContainerLogs(id, tail: tail);
|
|
}
|