feat(profile): 实现个人资料编辑与策略本地缓存

- 将资料编辑页重构为可交互表单,支持昵称、签名编辑与头像更换
- 新增 DioClient 本地缓存读取与写入方法,支持离线读取策略快照
- 设备策略切换后自动使本地缓存失效,避免数据不一致
- Home Tab 切换时选中态跟随可见页面,滑动过程中实时更新底栏高亮
- 系统设置页引入 loading 遮罩层,防止切换开关时重复操作
- 个人资料页接入 profileController 展示真实用户信息与加载状态
- 适配深色模式,修正 home_tab 中头像与文字颜色硬编码问题
This commit is contained in:
tongtong committed 2026-11-09 09:24:51 +08:00
1 parent 5f84a64c3e
commit e06e12fbbc
30 files changed
+2059 -336

No files matched your search

@@ -6,6 +6,8 @@ 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';
@@ -28,46 +30,67 @@ class SystemSettingsPage extends ConsumerWidget {
final sn = ref.watch(selectedDeviceSnProvider);
final policyAsync = sn == null
? const AsyncValue<DevicePolicy?>.data(null)
: ref.watch(devicePolicyProvider(sn));
: 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) return;
if (didPop || busy) return;
if (context.canPop()) {
context.pop();
} else {
context.go('/home');
}
},
child: AppPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: DeviceContextTitle(l10n.ssTitle),
leading: CupertinoButton(
padding: EdgeInsets.zero,
child: const Icon(CupertinoIcons.back),
onPressed: () => context.pop(),
),
),
child: SafeArea(
child: policyAsync.when(
loading: () => const Center(child: CupertinoActivityIndicator()),
error: (e, _) => Center(
child: Text(l10n.commonLoadFailed,
style: TextStyle(color: DarkMode.color(context, AppColors.sub))),
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),
),
),
),
),
data: (data) {
if (data == null) {
return Center(
child: Text(l10n.ssLoadFailed,
style: TextStyle(color: DarkMode.color(context, AppColors.sub))),
);
}
return _buildGroups(context, ref, l10n, sn, data);
},
),
),
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),
),
),
),
],
],
),
);
}
@@ -181,54 +204,39 @@ class SystemSettingsPage extends ConsumerWidget {
Expanded(
child: Text(
item.label,
style: TextStyle(fontSize: 14.5, color: DarkMode.color(context, AppColors.ink)),
style: TextStyle(
fontSize: 14.5,
color: DarkMode.color(context, AppColors.ink),
),
),
),
CupertinoSwitch(
value: enabled,
activeColor: AppColors.green,
onChanged: (value) =>
_onToggle(context, ref, l10n, sn, item.field, value ? 1 : 0),
activeTrackColor: AppColors.green,
onChanged:
sn == null ||
ref.watch(systemSettingsControllerProvider(sn)).isLoading
? null
: (value) => ref
.read(systemSettingsControllerProvider(sn).notifier)
.toggle(item.field, value),
),
],
),
);
}
/// 调用 toggle 接口并刷新策略状态。
Future<void> _onToggle(
BuildContext context,
WidgetRef ref,
AppLocalizations l10n,
String? sn,
String field,
int value,
) async {
if (sn == null || sn.isEmpty) {
_showToast(context, l10n.opCmdFailed);
return;
}
final error = await ref
.read(deviceRepositoryProvider)
.togglePolicy(sn, field, value);
if (!context.mounted) return;
if (error == null) {
// 成功后仅刷新该策略数据,保证开关状态与后台一致。
ref.invalidate(devicePolicyProvider(sn));
} else {
_showToast(context, error);
}
}
/// 轻提示:以 SnackBar 展示结果,避免连续切换时被弹窗打断。
void _showToast(BuildContext context, String message) {
ScaffoldMessenger.of(context)
..clearSnackBars()
..showSnackBar(SnackBar(
content: Text(message),
duration: const Duration(seconds: 2),
behavior: SnackBarBehavior.floating,
));
..showSnackBar(
SnackBar(
content: Text(message),
duration: const Duration(seconds: 2),
behavior: SnackBarBehavior.floating,
),
);
}
}