- 将资料编辑页重构为可交互表单,支持昵称、签名编辑与头像更换 - 新增 DioClient 本地缓存读取与写入方法,支持离线读取策略快照 - 设备策略切换后自动使本地缓存失效,避免数据不一致 - Home Tab 切换时选中态跟随可见页面,滑动过程中实时更新底栏高亮 - 系统设置页引入 loading 遮罩层,防止切换开关时重复操作 - 个人资料页接入 profileController 展示真实用户信息与加载状态 - 适配深色模式,修正 home_tab 中头像与文字颜色硬编码问题
258 lines
8.6 KiB
Dart
258 lines
8.6 KiB
Dart
import 'package:cupertino_ui/cupertino_ui.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:material_ui/material_ui.dart';
|
|
import 'package:ttstd_family_care/app/theme/dark_mode.dart';
|
|
import 'package:ttstd_family_care/core/widgets/app_page_scaffold.dart';
|
|
|
|
import '../../../core/widgets/feature_ui.dart';
|
|
import '../../../core/network/error_message.dart';
|
|
import 'system_settings_controller.dart';
|
|
import '../../../features/device/data/device_providers.dart';
|
|
import '../../../features/device/domain/device_models.dart';
|
|
import '../../../features/device/presentation/device_switcher.dart';
|
|
import '../../../l10n/app_localizations.dart';
|
|
|
|
/// 系统设置页(首页 → 常用功能 → 系统设置)。
|
|
///
|
|
/// 对接后端 client 策略接口:
|
|
/// - `GET /api/v1/client/sn/policy` 获取当前设备的功能开关状态
|
|
/// - `PUT /api/v1/client/sn/policy/toggle` 单独设置某个功能开关
|
|
///
|
|
/// 页面以分组列表展示后台 `DevicePolicyVO` 暴露的全部策略开关,逐项开关;
|
|
/// 每次切换即时调用 toggle 接口并刷新当前项状态。
|
|
class SystemSettingsPage extends ConsumerWidget {
|
|
const SystemSettingsPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final l10n = AppLocalizations.of(context);
|
|
final sn = ref.watch(selectedDeviceSnProvider);
|
|
final policyAsync = sn == null
|
|
? const AsyncValue<DevicePolicy?>.data(null)
|
|
: ref.watch(systemSettingsControllerProvider(sn));
|
|
final policy = policyAsync.valueOrNull;
|
|
final busy = policyAsync.isLoading;
|
|
if (sn != null) {
|
|
ref.listen(systemSettingsControllerProvider(sn), (previous, next) {
|
|
if (next.hasError && previous?.error != next.error) {
|
|
_showToast(context, userMessageOf(next.error!));
|
|
}
|
|
});
|
|
}
|
|
|
|
return PopScope(
|
|
canPop: false,
|
|
onPopInvokedWithResult: (didPop, _) {
|
|
if (didPop || busy) return;
|
|
if (context.canPop()) {
|
|
context.pop();
|
|
} else {
|
|
context.go('/home');
|
|
}
|
|
},
|
|
child: Stack(
|
|
children: [
|
|
AppPageScaffold(
|
|
navigationBar: CupertinoNavigationBar(
|
|
middle: DeviceContextTitle(l10n.ssTitle),
|
|
leading: CupertinoButton(
|
|
padding: EdgeInsets.zero,
|
|
onPressed: busy ? null : () => context.pop(),
|
|
child: const Icon(CupertinoIcons.back),
|
|
),
|
|
),
|
|
child: SafeArea(
|
|
child: policy != null
|
|
? _buildGroups(context, ref, l10n, sn, policy)
|
|
: Center(
|
|
child: busy
|
|
? const SizedBox.shrink()
|
|
: Text(
|
|
l10n.ssLoadFailed,
|
|
style: TextStyle(
|
|
color: DarkMode.color(context, AppColors.sub),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
if (busy) ...[
|
|
const Positioned.fill(
|
|
child: ModalBarrier(dismissible: false, color: Color(0x55000000)),
|
|
),
|
|
const Center(
|
|
child: CupertinoPopupSurface(
|
|
child: Padding(
|
|
padding: EdgeInsets.all(28),
|
|
child: CupertinoActivityIndicator(radius: 14),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 按分组渲染策略开关列表。
|
|
Widget _buildGroups(
|
|
BuildContext context,
|
|
WidgetRef ref,
|
|
AppLocalizations l10n,
|
|
String? sn,
|
|
DevicePolicy policy,
|
|
) {
|
|
final groups = <_PolicyGroup>[
|
|
_PolicyGroup(
|
|
title: l10n.ssGrpNetwork,
|
|
items: [
|
|
_PolicyItem('wifiHotspot', l10n.ssWifiHotspot),
|
|
_PolicyItem('bluetooth', l10n.ssBluetooth),
|
|
_PolicyItem('bluetoothSharing', l10n.ssBluetoothSharing),
|
|
_PolicyItem('toggleAirplaneMode', l10n.ssAirplaneMode),
|
|
_PolicyItem('modifyMobileApn', l10n.ssModifyApn),
|
|
_PolicyItem('resetNetworkSettings', l10n.ssResetNetwork),
|
|
],
|
|
),
|
|
_PolicyGroup(
|
|
title: l10n.ssGrpDisplay,
|
|
items: [
|
|
_PolicyItem('wallpaper', l10n.ssWallpaper),
|
|
_PolicyItem('notificationBar', l10n.ssNotificationBar),
|
|
_PolicyItem('statusBarPullDown', l10n.ssStatusBarPullDown),
|
|
_PolicyItem('autoRotate', l10n.ssAutoRotate),
|
|
_PolicyItem('autoBrightness', l10n.ssAutoBrightness),
|
|
_PolicyItem('manualAdjustBrightness', l10n.ssManualBrightness),
|
|
_PolicyItem('eyeProtection', l10n.ssEyeProtection),
|
|
_PolicyItem('darkMode', l10n.ssDarkMode),
|
|
_PolicyItem('modifyScreenTimeout', l10n.ssScreenTimeout),
|
|
],
|
|
),
|
|
_PolicyGroup(
|
|
title: l10n.ssGrpSystem,
|
|
items: [
|
|
_PolicyItem('timeSetting', l10n.ssTimeSetting),
|
|
_PolicyItem('manualAdjustTimeZone', l10n.ssManualTimeZone),
|
|
_PolicyItem('modifySystemTimeZone', l10n.ssModifyTimeZone),
|
|
_PolicyItem('modifySystemLanguage', l10n.ssModifyLanguage),
|
|
_PolicyItem('systemNavBarShow', l10n.ssNavBarShow),
|
|
_PolicyItem('systemNavBarSetting', l10n.ssNavBarSetting),
|
|
_PolicyItem('navBarOptions', l10n.ssNavBarOptions),
|
|
_PolicyItem('safeBoot', l10n.ssSafeBoot),
|
|
_PolicyItem('otaUpgrade', l10n.ssOtaUpgrade),
|
|
],
|
|
),
|
|
_PolicyGroup(
|
|
title: l10n.ssGrpStorage,
|
|
items: [
|
|
_PolicyItem('usbData', l10n.ssUsbData),
|
|
_PolicyItem('usbFileTransfer', l10n.ssUsbFileTransfer),
|
|
_PolicyItem('storageCard', l10n.ssStorageCard),
|
|
_PolicyItem('mountPhysicalStorage', l10n.ssMountPhysicalStorage),
|
|
_PolicyItem('factoryReset', l10n.ssFactoryReset),
|
|
_PolicyItem('adbUsbDebug', l10n.ssAdbUsbDebug),
|
|
],
|
|
),
|
|
_PolicyGroup(
|
|
title: l10n.ssGrpApp,
|
|
items: [
|
|
_PolicyItem('installApps', l10n.ssInstallApps),
|
|
_PolicyItem('uninstallApps', l10n.ssUninstallApps),
|
|
_PolicyItem('camera', l10n.ssCamera),
|
|
_PolicyItem('modifyLocationSwitch', l10n.ssModifyLocation),
|
|
_PolicyItem('adjustGlobalVolume', l10n.ssGlobalVolume),
|
|
],
|
|
),
|
|
];
|
|
|
|
return ListView(
|
|
padding: const EdgeInsets.only(bottom: 24),
|
|
children: [
|
|
for (final group in groups) ...[
|
|
SectionTitle(group.title),
|
|
CardBox(
|
|
padding: EdgeInsets.zero,
|
|
child: Column(
|
|
children: [
|
|
for (var i = 0; i < group.items.length; i++) ...[
|
|
if (i > 0) const AppDivider(),
|
|
_buildToggle(context, ref, l10n, sn, policy, group.items[i]),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
],
|
|
],
|
|
);
|
|
}
|
|
|
|
/// 单个策略开关行。
|
|
Widget _buildToggle(
|
|
BuildContext context,
|
|
WidgetRef ref,
|
|
AppLocalizations l10n,
|
|
String? sn,
|
|
DevicePolicy policy,
|
|
_PolicyItem item,
|
|
) {
|
|
final enabled = policy.enabled(item.field);
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 6),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
item.label,
|
|
style: TextStyle(
|
|
fontSize: 14.5,
|
|
color: DarkMode.color(context, AppColors.ink),
|
|
),
|
|
),
|
|
),
|
|
CupertinoSwitch(
|
|
value: enabled,
|
|
activeTrackColor: AppColors.green,
|
|
onChanged:
|
|
sn == null ||
|
|
ref.watch(systemSettingsControllerProvider(sn)).isLoading
|
|
? null
|
|
: (value) => ref
|
|
.read(systemSettingsControllerProvider(sn).notifier)
|
|
.toggle(item.field, value),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 轻提示:以 SnackBar 展示结果,避免连续切换时被弹窗打断。
|
|
void _showToast(BuildContext context, String message) {
|
|
ScaffoldMessenger.of(context)
|
|
..clearSnackBars()
|
|
..showSnackBar(
|
|
SnackBar(
|
|
content: Text(message),
|
|
duration: const Duration(seconds: 2),
|
|
behavior: SnackBarBehavior.floating,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 策略开关分组。
|
|
class _PolicyGroup {
|
|
const _PolicyGroup({required this.title, required this.items});
|
|
|
|
final String title;
|
|
final List<_PolicyItem> items;
|
|
}
|
|
|
|
/// 单个策略开关项(field 对应后台策略字段名)。
|
|
class _PolicyItem {
|
|
const _PolicyItem(this.field, this.label);
|
|
|
|
final String field;
|
|
final String label;
|
|
}
|