feat(profile): 实现个人资料编辑与策略本地缓存
- 将资料编辑页重构为可交互表单,支持昵称、签名编辑与头像更换 - 新增 DioClient 本地缓存读取与写入方法,支持离线读取策略快照 - 设备策略切换后自动使本地缓存失效,避免数据不一致 - Home Tab 切换时选中态跟随可见页面,滑动过程中实时更新底栏高亮 - 系统设置页引入 loading 遮罩层,防止切换开关时重复操作 - 个人资料页接入 profileController 展示真实用户信息与加载状态 - 适配深色模式,修正 home_tab 中头像与文字颜色硬编码问题
This commit is contained in:
1 parent
5f84a64c3e
commit
e06e12fbbc
30 files changed
+2059
-336
No files matched your search
@@ -9,6 +9,8 @@ import '../../../features/device/data/device_providers.dart';
|
||||
import '../../../features/device/domain/device_models.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
import '../../auth/presentation/auth_controller.dart';
|
||||
import 'profile_avatar.dart';
|
||||
import 'profile_controller.dart';
|
||||
|
||||
/// 我的 Tab 内容(特性模块:profile / presentation)。
|
||||
///
|
||||
@@ -20,6 +22,8 @@ class ProfileTab extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final profileState = ref.watch(profileControllerProvider);
|
||||
final profile = profileState.profile;
|
||||
|
||||
return AppPageScaffold(
|
||||
child: SafeArea(
|
||||
@@ -31,23 +35,30 @@ class ProfileTab extends ConsumerWidget {
|
||||
padding: const EdgeInsets.all(18),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 58,
|
||||
height: 58,
|
||||
decoration: const BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
gradient: LinearGradient(
|
||||
colors: [AppColors.green, AppColors.blue],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
),
|
||||
child: const Center(
|
||||
child: Text('U',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: CupertinoColors.white)),
|
||||
GestureDetector(
|
||||
onTap: profileState.saving
|
||||
? null
|
||||
: () => context.push('/profile/edit'),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
ProfileAvatar(
|
||||
url: profile?.avatar,
|
||||
name: profile?.displayName ?? '',
|
||||
),
|
||||
if (profileState.loading && profile == null)
|
||||
const Positioned.fill(
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0x55000000),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: CupertinoActivityIndicator(
|
||||
color: CupertinoColors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
@@ -55,33 +66,70 @@ class ProfileTab extends ConsumerWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('用户名',
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: DarkMode.color(context, AppColors.ink))),
|
||||
Text(
|
||||
profile?.displayName.isNotEmpty == true
|
||||
? profile!.displayName
|
||||
: l10n.piName,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: DarkMode.color(context, AppColors.ink),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text('ID: u_8821 · 平板管家 Pro',
|
||||
Text(
|
||||
profile == null ? '' : 'ID: ${profile.id}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
color: DarkMode.color(context, AppColors.sub),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
// Reserve two signature lines before the profile arrives.
|
||||
SizedBox(
|
||||
height:
|
||||
(MediaQuery.textScalerOf(context).scale(12) * 1.3)
|
||||
.ceilToDouble() *
|
||||
2,
|
||||
child: Text(
|
||||
profile?.signature ?? '',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12.5,
|
||||
color: DarkMode.color(context, AppColors.sub))),
|
||||
fontSize: 12,
|
||||
height: 1.3,
|
||||
color: DarkMode.color(context, AppColors.sub),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () => context.push('/profile/edit'),
|
||||
onTap: profileState.saving
|
||||
? null
|
||||
: () => context.push('/profile/edit'),
|
||||
child: Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 14, vertical: 7),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 14,
|
||||
vertical: 7,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.green.withValues(alpha: 0.12),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Text(l10n.profileEdit,
|
||||
style: const TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.green)),
|
||||
child: Text(
|
||||
l10n.profileEdit,
|
||||
style: const TextStyle(
|
||||
fontSize: 12.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.green,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -100,16 +148,40 @@ class ProfileTab extends ConsumerWidget {
|
||||
padding: EdgeInsets.zero,
|
||||
child: Column(
|
||||
children: [
|
||||
_settingRow(context, '🔔', AppColors.teal, l10n.setNotify, '消息、设备状态提醒'),
|
||||
_settingRow(
|
||||
context,
|
||||
'🔔',
|
||||
AppColors.teal,
|
||||
l10n.setNotify,
|
||||
'消息、设备状态提醒',
|
||||
),
|
||||
const AppDivider(),
|
||||
_settingRow(context, '🔒', const Color(0xFF22C55E), l10n.setPrivacy, '定位、相册、权限管理'),
|
||||
_settingRow(
|
||||
context,
|
||||
'🔒',
|
||||
const Color(0xFF22C55E),
|
||||
l10n.setPrivacy,
|
||||
'定位、相册、权限管理',
|
||||
),
|
||||
const AppDivider(),
|
||||
_settingRow(context, '🛡️', AppColors.red, l10n.setSecurity, '登录设备、密码',
|
||||
onTap: () => context.push('/security')),
|
||||
_settingRow(
|
||||
context,
|
||||
'🛡️',
|
||||
AppColors.red,
|
||||
l10n.setSecurity,
|
||||
'登录设备、密码',
|
||||
onTap: () => context.push('/security'),
|
||||
),
|
||||
const AppDivider(),
|
||||
_settingRow(context, '❓', AppColors.gray, l10n.setHelp, null),
|
||||
const AppDivider(),
|
||||
_settingRow(context, 'ℹ️', const Color(0xFF64748B), l10n.setAbout, '平板管家 v3.2.1'),
|
||||
_settingRow(
|
||||
context,
|
||||
'ℹ️',
|
||||
const Color(0xFF64748B),
|
||||
l10n.setAbout,
|
||||
'平板管家 v3.2.1',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -126,7 +198,11 @@ class ProfileTab extends ConsumerWidget {
|
||||
color: DarkMode.color(context, AppColors.card),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
boxShadow: const [
|
||||
BoxShadow(color: Color(0x14141E3C), blurRadius: 16, offset: Offset(0, 4)),
|
||||
BoxShadow(
|
||||
color: Color(0x14141E3C),
|
||||
blurRadius: 16,
|
||||
offset: Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Center(
|
||||
@@ -152,7 +228,10 @@ class ProfileTab extends ConsumerWidget {
|
||||
}
|
||||
|
||||
Widget _boundDeviceCard(
|
||||
BuildContext context, WidgetRef ref, AppLocalizations l10n) {
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
final devicesAsync = ref.watch(myDevicesProvider);
|
||||
final device = ref.watch(currentDeviceProvider);
|
||||
return CardBox(
|
||||
@@ -162,116 +241,221 @@ class ProfileTab extends ConsumerWidget {
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
child: devicesAsync.when(
|
||||
loading: () => const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 24),
|
||||
child: Center(child: CupertinoActivityIndicator()),
|
||||
),
|
||||
error: (e, _) => Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text('${l10n.deviceLoadFailed}:$e',
|
||||
style: TextStyle(fontSize: 12, color: DarkMode.color(context, AppColors.sub))),
|
||||
),
|
||||
data: (_) {
|
||||
if (device == null) {
|
||||
// 无绑定设备时也可点击进入设备管理页添加设备。
|
||||
child: SizedBox(
|
||||
height:
|
||||
28 +
|
||||
((MediaQuery.textScalerOf(context).scale(14.5) * 1.3)
|
||||
.ceilToDouble() +
|
||||
2 +
|
||||
(MediaQuery.textScalerOf(context).scale(12) * 1.3)
|
||||
.ceilToDouble())
|
||||
.clamp(36.0, double.infinity),
|
||||
child: devicesAsync.when(
|
||||
loading: () => const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 24),
|
||||
child: Center(child: CupertinoActivityIndicator()),
|
||||
),
|
||||
error: (e, _) => Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text(
|
||||
'${l10n.deviceLoadFailed}:$e',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: DarkMode.color(context, AppColors.sub),
|
||||
),
|
||||
),
|
||||
),
|
||||
data: (_) {
|
||||
if (device == null) {
|
||||
// 无绑定设备时也可点击进入设备管理页添加设备。
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => context.push('/device/manage'),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.deviceNone,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: DarkMode.color(context, AppColors.sub),
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${l10n.deviceManageAdd} ›',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: AppColors.green,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => context.push('/device/manage'),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(l10n.deviceNone,
|
||||
style: TextStyle(fontSize: 13, color: DarkMode.color(context, AppColors.sub))),
|
||||
),
|
||||
Text('${l10n.deviceManageAdd} ›',
|
||||
style: const TextStyle(fontSize: 13, color: AppColors.green)),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: _deviceCard(context, device, l10n),
|
||||
);
|
||||
}
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () => context.push('/device/manage'),
|
||||
child: _deviceCard(context, device, l10n),
|
||||
);
|
||||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _deviceCard(BuildContext context, DeviceBrief device, AppLocalizations l10n) {
|
||||
Widget _deviceCard(
|
||||
BuildContext context,
|
||||
DeviceBrief device,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
final status = device.isOnline ? l10n.deviceOnline : l10n.deviceOffline;
|
||||
final sub = device.snModel?.isNotEmpty == true
|
||||
? '$status · ${device.snModel}'
|
||||
: status;
|
||||
return _deviceRow(context, '📱',
|
||||
device.isOnline ? AppColors.green : DarkMode.color(context, AppColors.track),
|
||||
device.snName?.isNotEmpty == true ? device.snName! : device.serialno, sub,
|
||||
l10n.deviceManage);
|
||||
return _deviceRow(
|
||||
context,
|
||||
'📱',
|
||||
device.isOnline
|
||||
? AppColors.green
|
||||
: DarkMode.color(context, AppColors.track),
|
||||
device.snName?.isNotEmpty == true ? device.snName! : device.serialno,
|
||||
sub,
|
||||
l10n.deviceManage,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _deviceRow(BuildContext context, String emoji, Color color, String title, String sub, String? action) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(11)),
|
||||
child: Center(child: Text(emoji, style: const TextStyle(fontSize: 17))),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: TextStyle(fontSize: 14.5, fontWeight: FontWeight.w600, color: DarkMode.color(context, AppColors.ink))),
|
||||
const SizedBox(height: 2),
|
||||
Text(sub, style: TextStyle(fontSize: 12, color: DarkMode.color(context, AppColors.sub))),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (action != null)
|
||||
Text('$action ›', style: TextStyle(fontSize: 13, color: DarkMode.color(context, AppColors.sub)))
|
||||
else
|
||||
const Text('›', style: TextStyle(fontSize: 16, color: Color(0xFFCBD2DC))),
|
||||
],
|
||||
Widget _deviceRow(
|
||||
BuildContext context,
|
||||
String emoji,
|
||||
Color color,
|
||||
String title,
|
||||
String sub,
|
||||
String? action,
|
||||
) => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(emoji, style: const TextStyle(fontSize: 17)),
|
||||
),
|
||||
),
|
||||
);
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 14.5,
|
||||
height: 1.3,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: DarkMode.color(context, AppColors.ink),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
sub,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
height: 1.3,
|
||||
color: DarkMode.color(context, AppColors.sub),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (action != null)
|
||||
Text(
|
||||
'$action ›',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: DarkMode.color(context, AppColors.sub),
|
||||
),
|
||||
)
|
||||
else
|
||||
const Text(
|
||||
'›',
|
||||
style: TextStyle(fontSize: 16, color: Color(0xFFCBD2DC)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _settingRow(BuildContext context, String emoji, Color color, String label, String? sub,
|
||||
{VoidCallback? onTap}) {
|
||||
Widget _settingRow(
|
||||
BuildContext context,
|
||||
String emoji,
|
||||
Color color,
|
||||
String label,
|
||||
String? sub, {
|
||||
VoidCallback? onTap,
|
||||
}) {
|
||||
final row = Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 13),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(11)),
|
||||
child: Center(child: Text(emoji, style: const TextStyle(fontSize: 17))),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 13),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
borderRadius: BorderRadius.circular(11),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(label, style: TextStyle(fontSize: 14.5, fontWeight: FontWeight.w600, color: DarkMode.color(context, AppColors.ink))),
|
||||
if (sub != null) ...[
|
||||
const SizedBox(height: 2),
|
||||
Text(sub, style: TextStyle(fontSize: 12, color: DarkMode.color(context, AppColors.sub))),
|
||||
],
|
||||
child: Center(
|
||||
child: Text(emoji, style: const TextStyle(fontSize: 17)),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 14.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: DarkMode.color(context, AppColors.ink),
|
||||
),
|
||||
),
|
||||
if (sub != null) ...[
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
sub,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
height: 1.3,
|
||||
color: DarkMode.color(context, AppColors.sub),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const Text('›', style: TextStyle(fontSize: 16, color: Color(0xFFCBD2DC))),
|
||||
],
|
||||
),
|
||||
);
|
||||
),
|
||||
const Text(
|
||||
'›',
|
||||
style: TextStyle(fontSize: 16, color: Color(0xFFCBD2DC)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (onTap == null) return row;
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
|
||||
Reference in new issue
Block a user