35 lines
1.4 KiB
Dart
35 lines
1.4 KiB
Dart
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);
|
|
}
|