8d890c0424
- 新增 lib/core/network/:ApiClient(dio 封装,错误信封→类型化异常,base URL 经 --dart-define=PATBOND_API_BASE_URL 注入)、AuthInterceptor(Bearer + 设备标识)、TokenRefresher(单飞刷新,401/40101 重放一次,仅 40102/再 401 清会话) - 新增 lib/features/auth/:SessionManager(token 只进 flutter_secure_storage)、AuthRepository(login/register/refresh/logout/me,注册带 Idempotency-Key)、Splash(500ms 最短停留/5s 超时/错误态重试+改用账号登录)、登录页与注册页(照 12 号组装稿,错误三层映射,预留区不渲染) - App 根组件改为认证状态机驱动(Splash↔登录↔主壳 300ms fade);个人中心退出登录接入真实 logout - 顺带修复:FIX-1 促销卡渐变改 [primaryStrong, primary]、FIX-2 补 helperStyle: muted、README dart format 命令补 --output=none - 新增依赖:dio ^5.11.1、flutter_secure_storage ^11.0.0、uuid ^4.6.0 - 门禁:dart format(0 changed)/ flutter analyze(No issues)/ flutter test(30 passed,其中新增 23:TokenRefresher 5 + AuthRepository 10 + 登录页 4 + 注册页 4) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
174 lines
5.6 KiB
Dart
174 lines
5.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:patbond_flutter/core/theme/app_theme.dart';
|
|
import 'package:patbond_flutter/data/demo_data.dart';
|
|
import 'package:patbond_flutter/state/app_state.dart';
|
|
import 'package:patbond_flutter/widgets/common.dart';
|
|
|
|
class ProfilePage extends StatelessWidget {
|
|
const ProfilePage({required this.appState, super.key, this.onLogout});
|
|
|
|
final AppState appState;
|
|
|
|
/// 真实退出登录入口;未接线时保持演示提示。
|
|
final Future<void> Function()? onLogout;
|
|
|
|
static const menuItems = [
|
|
(Icons.assignment_outlined, '我的预约订单', '查看进行中与历史服务'),
|
|
(Icons.bookmarks_outlined, '我的收藏与草稿', '已保存的宠物作品与攻略'),
|
|
(Icons.badge_outlined, '宠物健康卡包', '电子接种证与体检报告'),
|
|
(Icons.location_on_outlined, '地址与定位管理', '管理家庭住址与常用医院'),
|
|
(Icons.settings_outlined, '设置与关于', '隐私设置与版本信息'),
|
|
];
|
|
|
|
void showDemoMessage(BuildContext context, String name) {
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(SnackBar(content: Text('「$name」功能为演示入口')));
|
|
}
|
|
|
|
Future<void> reset(BuildContext context) async {
|
|
final confirmed = await showDialog<bool>(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
title: const Text('恢复演示数据'),
|
|
content: const Text('宠物资料、疫苗记录以及新增帖子都会恢复为初始状态。'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context, false),
|
|
child: const Text('取消'),
|
|
),
|
|
FilledButton(
|
|
onPressed: () => Navigator.pop(context, true),
|
|
child: const Text('确认恢复'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
if (confirmed == true) {
|
|
await appState.resetDemoData();
|
|
if (context.mounted) {
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(const SnackBar(content: Text('演示数据已恢复')));
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListView(
|
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 30),
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(24),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.ink,
|
|
borderRadius: BorderRadius.circular(30),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
RemoteImage(
|
|
url: userAvatar,
|
|
width: 82,
|
|
height: 82,
|
|
borderRadius: BorderRadius.circular(41),
|
|
),
|
|
const SizedBox(height: 12),
|
|
const Text(
|
|
'萌宠新手(豆豆家长)',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 17,
|
|
fontWeight: FontWeight.w800,
|
|
),
|
|
),
|
|
const SizedBox(height: 5),
|
|
const Text(
|
|
'Patbond 社区创作达人',
|
|
style: TextStyle(color: AppColors.accent, fontSize: 12),
|
|
),
|
|
const SizedBox(height: 20),
|
|
const Divider(color: Colors.white24),
|
|
const SizedBox(height: 10),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
const _ProfileStat(value: '24', label: '关注我'),
|
|
const _ProfileStat(value: '1.8k', label: '获赞'),
|
|
_ProfileStat(
|
|
value: '${appState.posts.length}',
|
|
label: '我的作品',
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const SizedBox(height: 18),
|
|
SectionCard(
|
|
padding: const EdgeInsets.symmetric(vertical: 6),
|
|
child: Column(
|
|
children: menuItems.map((item) {
|
|
return ListTile(
|
|
leading: CircleAvatar(
|
|
backgroundColor: AppColors.surfaceTint,
|
|
child: Icon(item.$1, color: AppColors.primary),
|
|
),
|
|
title: Text(
|
|
item.$2,
|
|
style: const TextStyle(fontWeight: FontWeight.w700),
|
|
),
|
|
subtitle: Text(item.$3),
|
|
trailing: const Icon(Icons.chevron_right),
|
|
onTap: () => showDemoMessage(context, item.$2),
|
|
);
|
|
}).toList(),
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
OutlinedButton.icon(
|
|
style: OutlinedButton.styleFrom(
|
|
minimumSize: const Size.fromHeight(50),
|
|
),
|
|
onPressed: () => reset(context),
|
|
icon: const Icon(Icons.restart_alt),
|
|
label: const Text('恢复演示数据'),
|
|
),
|
|
const SizedBox(height: 10),
|
|
TextButton(
|
|
onPressed: onLogout ?? () => showDemoMessage(context, '退出登录'),
|
|
child: const Text('切换账号或退出登录'),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ProfileStat extends StatelessWidget {
|
|
const _ProfileStat({required this.value, required this.label});
|
|
|
|
final String value;
|
|
final String label;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
children: [
|
|
Text(
|
|
value,
|
|
style: const TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 17,
|
|
fontWeight: FontWeight.w900,
|
|
),
|
|
),
|
|
const SizedBox(height: 3),
|
|
Text(
|
|
label,
|
|
style: const TextStyle(color: Colors.white70, fontSize: 11),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|