所有数据库表,提供相应的provider、桥接等方法
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:im_app/app/di/db_provider.dart';
|
||||
import 'package:im_app/data/repositories/workspace_repository_impl.dart';
|
||||
import 'package:im_app/domain/entities/workspace.dart';
|
||||
import 'package:im_app/domain/repositories/workspace_repository.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'workspace_provider.g.dart';
|
||||
|
||||
// ── Repository ────────────────────────────────────────────────────────────────
|
||||
|
||||
final workspaceRepositoryProvider = Provider<WorkspaceRepository>((ref) {
|
||||
return WorkspaceRepositoryImpl(ref.watch(storageSdkProvider));
|
||||
});
|
||||
|
||||
// ── Streams ───────────────────────────────────────────────────────────────────
|
||||
|
||||
/// 监听所有工作空间
|
||||
@riverpod
|
||||
Stream<List<Workspace>> allWorkspaces(Ref ref) {
|
||||
return ref.watch(workspaceRepositoryProvider).watchAll();
|
||||
}
|
||||
|
||||
/// 监听指定工作空间
|
||||
@riverpod
|
||||
Stream<Workspace?> workspaceById(Ref ref, int id) {
|
||||
return ref.watch(workspaceRepositoryProvider).watchById(id);
|
||||
}
|
||||
Reference in New Issue
Block a user