Files
ttstd_family_care/lib/features/device/data/device_providers.dart
T
TongTongStudio 06cdc77172 feat(android): 支持沉浸式状态栏、地图定位与自定义签名
- 配置 edge-to-edge 沉浸式状态栏与刘海屏适配
- 新增百度地图权限、AK 配置及定位权限说明
- 接入 MethodChannel 实现返回键退后台热启动优化
- 配置自定义签名并更新构建逻辑
- 完善 token 刷新与鉴权失效统一处理
- 新增地图页与截图页路由
- 修复返回键拦截导致的 PopScope 失效问题
2026-08-19 03:43:12 +08:00

62 lines
2.3 KiB
Dart

import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:ttstd_family_care/features/device/data/device_api.dart';
import 'package:ttstd_family_care/features/device/data/device_repository_impl.dart';
import 'package:ttstd_family_care/features/device/domain/device_models.dart';
import 'package:ttstd_family_care/features/device/domain/device_repository.dart';
/// 设备仓储 Provider。
final deviceRepositoryProvider = Provider<DeviceRepository>((ref) {
const api = DeviceApi();
return DeviceRepositoryImpl(api);
});
/// 当前用户已绑定设备列表。
final myDevicesProvider = FutureProvider<List<DeviceBrief>>((ref) async {
final repo = ref.watch(deviceRepositoryProvider);
return repo.getMyDevices();
});
/// 当前选中的设备序列号(默认取绑定列表首个设备)。
///
/// 使用普通 Provider(而非 StateProvider)以便随 [myDevicesProvider] 的加载完成
/// 自动推导出首个已绑定设备的 SN。若后续需要手动切换设备,可改为 StateProvider。
final selectedDeviceSnProvider = Provider<String?>((ref) {
final devices = ref.watch(myDevicesProvider);
return devices.maybeWhen(
data: (list) => list.isEmpty ? null : list.first.serialno,
orElse: () => null,
);
});
/// 按 SN 获取设备基本信息。
final deviceInfoProvider =
FutureProvider.family<DeviceSystemInfo?, String>((ref, sn) async {
if (sn.isEmpty) return null;
final repo = ref.watch(deviceRepositoryProvider);
return repo.getDeviceInfo(sn);
});
/// 按 SN 获取设备最新定位信息。
final deviceLocationProvider =
FutureProvider.family<DeviceLocation?, String>((ref, sn) async {
if (sn.isEmpty) return null;
final repo = ref.watch(deviceRepositoryProvider);
return repo.getLocation(sn);
});
/// 按 SN 获取设备已安装应用列表。
final deviceApksProvider =
FutureProvider.family<List<DeviceApkInfo>, String>((ref, sn) async {
if (sn.isEmpty) return const [];
final repo = ref.watch(deviceRepositoryProvider);
return repo.getApks(sn);
});
/// 按 SN 获取设备最近截图列表。
final recentScreenshotsProvider =
FutureProvider.family<List<ScreenshotVO>, String>((ref, sn) async {
if (sn.isEmpty) return const [];
final repo = ref.watch(deviceRepositoryProvider);
return repo.getRecentScreenshots(sn);
});