Files
AI-Health/health_app/lib/pages/profile/profile_page.dart
MingNian 6e69f1085e chore: 全面规范化代码,遵循 CLAUDE.md 编码规范
- C# 文件命名改为 snake_case(28 个文件重命名)
- C# 类转换为主构造函数(8 个类)
- 空 catch 添加异常类型(2 处)
- 新建 GlobalUsings.cs(Health.Infrastructure、Health.WebApi)
- Flutter 移除 go_router,改用 Riverpod 路由栈
- Flutter 移除 flutter_secure_storage,改用 sqflite 持久化
- 修复 Flutter 构建路径(Flutter SDK 迁至 D 盘)
- 后端端口改为 0.0.0.0:5000,支持局域网访问
2026-06-02 12:41:06 +08:00

70 lines
3.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/navigation_provider.dart';
import '../../providers/auth_provider.dart';
/// 个人中心页面
class ProfilePage extends ConsumerWidget {
const ProfilePage({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final auth = ref.watch(authProvider);
final user = auth.user;
return Scaffold(
appBar: AppBar(title: const Text('个人中心')),
body: ListView(
children: [
// 头像区
Container(
padding: const EdgeInsets.all(24),
color: const Color(0xFFEDEBFF),
child: Column(
children: [
CircleAvatar(
radius: 40,
backgroundColor: const Color(0xFF635BFF),
child: Text(
(user?.name ?? '?')[0],
style: const TextStyle(fontSize: 32, color: Colors.white),
),
),
const SizedBox(height: 12),
Text(user?.name ?? '未设置', style: Theme.of(context).textTheme.titleLarge),
const SizedBox(height: 4),
Text(user?.phone ?? '', style: Theme.of(context).textTheme.bodyMedium),
],
),
),
const SizedBox(height: 8),
_MenuItem(icon: Icons.person, title: '编辑资料', onTap: () => pushRoute(ref, 'profileEdit')),
_MenuItem(icon: Icons.folder, title: '健康档案', onTap: () => pushRoute(ref, 'healthArchive')),
_MenuItem(icon: Icons.devices, title: '设备管理', onTap: () {}),
const Divider(),
_MenuItem(icon: Icons.settings, title: '设置', onTap: () => pushRoute(ref, 'settings')),
_MenuItem(icon: Icons.info, title: '关于', onTap: () => pushRoute(ref, 'staticText', params: {'type': 'about'})),
const Divider(),
_MenuItem(
icon: Icons.logout, title: '退出登录', textColor: const Color(0xFFE53935),
onTap: () async {
final ok = await showDialog<bool>(context: context, builder: (ctx) => AlertDialog(
title: const Text('退出登录'), content: const Text('确定退出?'),
actions: [TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('取消')),
TextButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('确定'))]));
if (ok == true) { await ref.read(authProvider.notifier).logout(); goRoute(ref, 'login'); }
},
),
],
),
);
}
}
class _MenuItem extends StatelessWidget {
final IconData icon; final String title; final VoidCallback onTap; final Color? textColor;
const _MenuItem({required this.icon, required this.title, required this.onTap, this.textColor});
@override
Widget build(BuildContext context) => ListTile(leading: Icon(icon, color: const Color(0xFF666666)), title: Text(title, style: TextStyle(fontSize: 16, color: textColor ?? const Color(0xFF1A1A1A))), trailing: const Icon(Icons.chevron_right, size: 20), onTap: onTap);
}