25 lines
1.1 KiB
Dart
25 lines
1.1 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:ttstd_family_care/features/contacts/data/contact_api.dart';
|
|
import 'package:ttstd_family_care/features/contacts/data/contact_repository_impl.dart';
|
|
import 'package:ttstd_family_care/features/contacts/domain/contact_models.dart';
|
|
import 'package:ttstd_family_care/features/contacts/domain/contact_repository.dart';
|
|
import 'package:ttstd_family_care/features/device/data/device_providers.dart';
|
|
|
|
/// 联系人仓储 Provider。
|
|
final contactRepositoryProvider = Provider<ContactRepository>((ref) {
|
|
const api = ContactApi();
|
|
return ContactRepositoryImpl(api);
|
|
});
|
|
|
|
/// 当前选中设备的联系人列表。
|
|
///
|
|
/// 依赖 [selectedDeviceSnProvider] 选择设备;未绑定设备时返回空列表。
|
|
/// 通过 [autoDispose] 避免切换设备后残留旧数据。
|
|
final contactsProvider =
|
|
FutureProvider.autoDispose<List<Contact>>((ref) async {
|
|
final sn = ref.watch(selectedDeviceSnProvider);
|
|
if (sn == null || sn.isEmpty) return const [];
|
|
final repo = ref.watch(contactRepositoryProvider);
|
|
return repo.getContacts(sn);
|
|
});
|