所有数据库表,提供相应的provider、桥接等方法
This commit is contained in:
34
apps/im_app/lib/app/di/sound_provider.dart
Normal file
34
apps/im_app/lib/app/di/sound_provider.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:im_app/app/di/db_provider.dart';
|
||||
import 'package:im_app/data/repositories/sound_repository_impl.dart';
|
||||
import 'package:im_app/domain/entities/sound.dart';
|
||||
import 'package:im_app/domain/repositories/sound_repository.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
part 'sound_provider.g.dart';
|
||||
|
||||
// ── Repository ────────────────────────────────────────────────────────────────
|
||||
|
||||
final soundRepositoryProvider = Provider<SoundRepository>((ref) {
|
||||
return SoundRepositoryImpl(ref.watch(storageSdkProvider));
|
||||
});
|
||||
|
||||
// ── Streams ───────────────────────────────────────────────────────────────────
|
||||
|
||||
/// 监听所有音效
|
||||
@riverpod
|
||||
Stream<List<Sound>> allSounds(Ref ref) {
|
||||
return ref.watch(soundRepositoryProvider).watchAll();
|
||||
}
|
||||
|
||||
/// 监听指定类型音效
|
||||
@riverpod
|
||||
Stream<List<Sound>> soundsByType(Ref ref, int typ) {
|
||||
return ref.watch(soundRepositoryProvider).watchByType(typ);
|
||||
}
|
||||
|
||||
/// 监听指定音效
|
||||
@riverpod
|
||||
Stream<Sound?> soundById(Ref ref, int id) {
|
||||
return ref.watch(soundRepositoryProvider).watchById(id);
|
||||
}
|
||||
Reference in New Issue
Block a user