- 引入 DarkMode 工具类,提供系统栏、颜色、色调的暗色适配能力 - AppColors 调色板改为 CupertinoDynamicColor.withBrightness 自适应 - app.dart 增加 AnnotatedRegion 与 Material Theme 包裹以联动暗色系统栏 - 移除 system_ui_util 中硬编码的浅色图标配置,改由主题驱动 - CardBox、AppDivider、SectionTitle 等公共组件适配深色卡片与分割线 - settings_ui、change_mobile、change_password、login_devices、wechat_binding 等页面全面接入 DarkMode 颜色 - dio_client 新增 allowStale 响应缓存机制,网络异常时回退本地缓存 - token_storage 增加 currentAccountId(JWT 解析)及按用户隔离的设备偏好存取 - ApiException 改为通过私有构造持有真实 AppError 实例,appError getter 返回结构化错误 - 闹钟模块迁移至 FutureProvider.autoDispose.family,消除手动 loading 状态管理 - 闹钟编辑页 CupertinoTimerPicker 替换为 CupertinoDatePicker(24h 格式),标签输入改为 TextEditingController
96 lines
3.4 KiB
Dart
96 lines
3.4 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';
|
|
|
|
import '../../../core/storage/token_storage.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();
|
|
});
|
|
|
|
/// 用户手动选择的设备 SN。
|
|
///
|
|
/// 为空或对应设备已解绑时,[currentDeviceProvider] 自动回退到绑定列表首个设备,
|
|
/// 因此切换设备只需写入此状态。
|
|
final selectedDeviceSnOverrideProvider =
|
|
NotifierProvider<SelectedDeviceSn, String?>(SelectedDeviceSn.new);
|
|
|
|
class SelectedDeviceSn extends Notifier<String?> {
|
|
@override
|
|
String? build() => TokenStorage.selectedDeviceSn;
|
|
|
|
void select(String serialno) {
|
|
TokenStorage.saveSelectedDeviceSn(serialno);
|
|
state = serialno;
|
|
}
|
|
}
|
|
|
|
/// 当前正在查看的设备(未绑定设备时为 null)。
|
|
///
|
|
/// 绑定多个设备时以用户选择为准;刷新列表期间保留上一次数据,
|
|
/// 解绑当前设备后自动落到新列表首个设备。
|
|
final currentDeviceProvider = Provider<DeviceBrief?>((ref) {
|
|
final list = ref.watch(myDevicesProvider).value ?? const <DeviceBrief>[];
|
|
if (list.isEmpty) return null;
|
|
final selectedSn = ref.watch(selectedDeviceSnOverrideProvider);
|
|
for (final device in list) {
|
|
if (device.serialno == selectedSn) return device;
|
|
}
|
|
return list.first;
|
|
});
|
|
|
|
/// 当前选中的设备序列号(默认取绑定列表首个设备)。
|
|
final selectedDeviceSnProvider = Provider<String?>(
|
|
(ref) => ref.watch(currentDeviceProvider)?.serialno,
|
|
);
|
|
|
|
/// 按 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);
|
|
});
|
|
|
|
/// 按 SN 获取设备策略信息(功能开关)。
|
|
final devicePolicyProvider =
|
|
FutureProvider.family<DevicePolicy?, String>((ref, sn) async {
|
|
if (sn.isEmpty) return null;
|
|
final repo = ref.watch(deviceRepositoryProvider);
|
|
return repo.getPolicy(sn);
|
|
});
|