Files
AI-Health/health_app/lib/widgets/health_drawer.dart
MingNian 01cd132476 feat: 医生端完整实现 + 双角色登录 + 健康日历 + 饮食记录重做 + 配色系统重构
后端:
- User表加Role字段 + DoctorProfile表 + 废弃旧Doctor数据
- JWT加Role claim + 注册/登录拆分(/api/auth/register + /api/auth/login)
- 医生端点全量加JWT鉴权+Role校验(15个端点)
- 日历端点改造(用药/运动/随访按日期+星期匹配)
- 饮食记录PUT端点 + 健康记录DELETE端点
- 用户Profile端点返回Role

前端:
- 登录页重做(角色选择卡片 用户紫/医生蓝 + 审核码6666 + 注册返登录)
- App路由分流(userRole→患者端/医生端)
- 医生端: 工作台Dashboard + 患者管理(搜索分页) + 问诊/报告/随访CRUD
- 报告审核: AI预分析+指标表格+严重程度4级+模板多选+评语
- 随访编辑: 患者选择器+日期时间+打通患者端
- 健康日历: 可点击日历+当日安排列表+用药/运动/随访颜色标记
- 饮食记录: 热量趋势7/30天+日历(一周)+当日胶囊详情+侧滑编辑删除
- 健康档案: 日期选择器+手术可添加多条+白底渐变保存按钮
- 配色系统: 清理25个未使用色+新增doctorBlue/drawerGradient/pageGrey
- 患者端侧边栏: 新渐变+白底按钮+紫色汉堡图标
- AI对话: 用户气泡白底黑字+药管家改蓝色
- App启动闪屏: 防登录页闪烁

文档: color_design_system.md(20页面完整配色设计+图标底色对照表)
2026-06-14 23:28:14 +08:00

348 lines
15 KiB
Dart

import 'package:flutter/material.dart';
import '../core/app_theme.dart';
import '../core/app_colors.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../core/navigation_provider.dart';
import '../providers/auth_provider.dart';
import '../providers/data_providers.dart';
import 'service_package_card.dart';
class HealthDrawer extends ConsumerWidget {
const HealthDrawer({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
final auth = ref.watch(authProvider);
final user = auth.user;
final latestHealth = ref.watch(latestHealthProvider);
return Drawer(
width: MediaQuery.of(context).size.width * 0.85,
child: Container(
decoration: const BoxDecoration(gradient: AppColors.drawerGradient),
child: SafeArea(
child: ListView(
padding: const EdgeInsets.fromLTRB(14, 12, 14, 0),
children: [
// 个人信息 + 蓝牙 + 健康档案 — 合并为一个卡片
_buildTopCard(user, ref),
const SizedBox(height: 8),
_buildHealthSection(latestHealth, ref),
const SizedBox(height: 8),
_buildFeatureSection(ref),
const SizedBox(height: 8),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(AppTheme.rMd),
border: Border.all(color: Color(0xFFC8DDFD), width: 1.5),
boxShadow: [AppTheme.shadowCard],
),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 14, 16, 0),
child: Container(
decoration: BoxDecoration(
gradient: AppColors.primaryGradient,
borderRadius: BorderRadius.circular(AppTheme.rPill),
boxShadow: AppColors.buttonShadow,
),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
child: const Row(mainAxisSize: MainAxisSize.min, children: [
Icon(Icons.workspace_premium_rounded, size: 16, color: Colors.white),
SizedBox(width: 4),
Text('VIP服务', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w700, color: Colors.white)),
]),
),
),
const ServicePackageCard(compact: true),
]),
),
const SizedBox(height: 8),
// 保险栏
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(AppTheme.rMd),
border: Border.all(color: Color(0xFFC8DDFD), width: 1.5),
boxShadow: [AppTheme.shadowCard],
),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 14, 16, 0),
child: Container(
decoration: BoxDecoration(
gradient: AppColors.primaryGradient,
borderRadius: BorderRadius.circular(AppTheme.rPill),
boxShadow: AppColors.buttonShadow,
),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
child: const Row(mainAxisSize: MainAxisSize.min, children: [
Icon(Icons.shield_rounded, size: 16, color: Colors.white),
SizedBox(width: 4),
Text('保险', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w700, color: Colors.white)),
]),
),
),
const SizedBox(height: 14),
const Padding(
padding: EdgeInsets.fromLTRB(16, 0, 16, 14),
child: Text('即将上线,敬请期待', style: TextStyle(fontSize: 14, color: AppColors.textHint)),
),
]),
),
const SizedBox(height: 8),
],
),
),
),
);
}
// ════════════ 顶部区域(个人信息 + 设置 + 快捷入口,无框融入背景) ═══════════
Widget _buildTopCard(dynamic user, WidgetRef ref) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 2),
child: Column(children: [
// 第一行:个人信息(窄)+ 设置按钮
Padding(
padding: const EdgeInsets.fromLTRB(12, 4, 8, 0),
child: Row(children: [
// 用户头像+名称 — 占70%
Expanded(
flex: 7,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => pushRoute(ref, 'profile'),
child: Row(children: [
Container(
width: 44, height: 44,
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
child: const Icon(Icons.person, size: 24, color: AppColors.textHint),
),
const SizedBox(width: 10),
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(user?.name ?? '未设置昵称', style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w700, color: AppColors.textPrimary), overflow: TextOverflow.ellipsis),
Text(user?.phone ?? '未登录', style: const TextStyle(fontSize: 12, color: AppColors.textSecondary)),
])),
]),
),
),
// 设置按钮 — 占30%
Expanded(
flex: 3,
child: GestureDetector(
onTap: () => pushRoute(ref, 'settings'),
child: Container(
height: 44,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(AppTheme.rSm),
),
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
const Icon(Icons.settings_outlined, size: 22, color: AppColors.primary),
const SizedBox(height: 2),
const Text('设置', style: TextStyle(fontSize: 11, color: AppColors.primary)),
]),
),
),
),
]),
),
const SizedBox(height: 16),
// 第二行:蓝牙 + 健康档案 — 白色底
Row(children: [
Expanded(child: _QuickEntry(Icons.bluetooth_rounded, '蓝牙设备', () => pushRoute(ref, 'devices'))),
const SizedBox(width: 12),
Expanded(child: _QuickEntry(Icons.folder_outlined, '健康档案', () => pushRoute(ref, 'healthArchive'))),
]),
]),
);
}
Widget _QuickEntry(IconData icon, String label, VoidCallback onTap) {
return GestureDetector(
onTap: onTap,
child: Container(
padding: const EdgeInsets.symmetric(vertical: 18),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(AppTheme.rMd),
border: Border.all(color: Color(0xFFC8DDFD), width: 1.5),
),
child: Column(children: [
Icon(icon, size: 28, color: AppColors.primary),
const SizedBox(height: 6),
Text(label, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: AppColors.textPrimary)),
]),
),
);
}
// ════════════ 健康仪表盘 ════════════
Widget _buildHealthSection(AsyncValue<Map<String, dynamic>> latestHealth, WidgetRef ref) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(AppTheme.rLg),
border: Border.all(color: Color(0xFFC8DDFD), width: 1.5),
boxShadow: [AppTheme.shadowCard],
),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 14, 16, 4),
child: Row(children: [
Container(
decoration: BoxDecoration(
gradient: AppColors.primaryGradient,
borderRadius: BorderRadius.circular(AppTheme.rPill),
boxShadow: AppColors.buttonShadow,
),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
child: const Row(mainAxisSize: MainAxisSize.min, children: [
Icon(Icons.dashboard_rounded, size: 16, color: Colors.white),
SizedBox(width: 4),
Text('健康仪表盘', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w700, color: Colors.white)),
]),
),
const Spacer(),
GestureDetector(
onTap: () => pushRoute(ref, 'trend'),
child: const Padding(padding: EdgeInsets.all(4), child: Text('详情', style: TextStyle(fontSize: 13, color: AppColors.textHint))),
),
]),
),
latestHealth.when(
data: (data) => Padding(
padding: const EdgeInsets.fromLTRB(12, 4, 12, 14),
child: Row(children: [
_MiniMetric(Icons.favorite_rounded, '血压', _bpText(data['BloodPressure']), () => pushRoute(ref, 'trend', params: {'type': 'blood_pressure'})),
_MiniMetric(Icons.monitor_heart_outlined, '心率', _metricVal(data['HeartRate']), () => pushRoute(ref, 'trend', params: {'type': 'heart_rate'})),
_MiniMetric(Icons.bloodtype_outlined, '血糖', _metricVal(data['Glucose']), () => pushRoute(ref, 'trend', params: {'type': 'glucose'})),
_MiniMetric(Icons.air_outlined, '血氧', _metricVal(data['SpO2']), () => pushRoute(ref, 'trend', params: {'type': 'spo2'})),
_MiniMetric(Icons.monitor_weight_outlined, '体重', _metricVal(data['Weight']), () => pushRoute(ref, 'trend', params: {'type': 'weight'})),
]),
),
loading: () => const Padding(padding: EdgeInsets.all(20), child: Center(child: SizedBox(width: 22, height: 22, child: CircularProgressIndicator(strokeWidth: 2, color: AppColors.primary)))),
error: (_, __) => Padding(
padding: const EdgeInsets.fromLTRB(12, 4, 12, 14),
child: Row(children: [
_MiniMetric(Icons.favorite_rounded, '血压', '--'),
_MiniMetric(Icons.monitor_heart_outlined, '心率', '--'),
_MiniMetric(Icons.bloodtype_outlined, '血糖', '--'),
_MiniMetric(Icons.air_outlined, '血氧', '--'),
_MiniMetric(Icons.monitor_weight_outlined, '体重', '--'),
]),
),
),
]),
);
}
// ════════════ 功能区 ════════════
Widget _buildFeatureSection(WidgetRef ref) {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(AppTheme.rLg),
border: Border.all(color: Color(0xFFC8DDFD), width: 1.5),
boxShadow: [AppTheme.shadowCard],
),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Padding(
padding: const EdgeInsets.fromLTRB(16, 14, 16, 4),
child: Container(
decoration: BoxDecoration(
gradient: AppColors.primaryGradient,
borderRadius: BorderRadius.circular(AppTheme.rPill),
boxShadow: AppColors.buttonShadow,
),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
child: const Row(mainAxisSize: MainAxisSize.min, children: [
Icon(Icons.apps_rounded, size: 16, color: Colors.white),
SizedBox(width: 4),
Text('功能', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w700, color: Colors.white)),
]),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(12, 6, 12, 14),
child: Row(children: [
_FeatureChip(icon: Icons.description_outlined, label: '报告管理', onTap: () => pushRoute(ref, 'reports')),
_FeatureChip(icon: Icons.calendar_today_outlined, label: '健康日历', onTap: () => pushRoute(ref, 'calendar')),
_FeatureChip(icon: Icons.restaurant_outlined, label: '饮食记录', onTap: () => pushRoute(ref, 'dietRecords')),
_FeatureChip(icon: Icons.event_note_outlined, label: '复查随访', onTap: () => pushRoute(ref, 'followups')),
]),
),
]),
);
}
// ════════════ Helpers ════════════
String _bpText(dynamic bp) {
if (bp == null) return '--';
if (bp is Map) return '${bp['systolic'] ?? '--'}/${bp['diastolic'] ?? '--'}';
return '--';
}
String _metricVal(dynamic val) {
if (val == null) return '--';
if (val is num) return val.toStringAsFixed(val is double ? 1 : 0);
if (val is Map) return (val['value']?.toString() ?? '--');
return '--';
}
}
class _MiniMetric extends StatelessWidget {
final IconData icon; final String label; final String value; final VoidCallback? onTap;
const _MiniMetric(this.icon, this.label, this.value, [this.onTap]);
@override
Widget build(BuildContext context) {
return Expanded(
child: GestureDetector(
onTap: onTap,
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 2),
padding: const EdgeInsets.symmetric(vertical: 10),
decoration: BoxDecoration(
gradient: AppColors.bgGradient,
borderRadius: BorderRadius.circular(AppTheme.rSm),
),
child: Column(mainAxisSize: MainAxisSize.min, children: [
Icon(icon, size: 24, color: AppColors.primary),
const SizedBox(height: 5),
Text(value, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w800, color: AppColors.textPrimary)),
Text(label, style: const TextStyle(fontSize: 12, color: AppColors.textHint)),
]),
),
),
);
}
}
class _FeatureChip extends StatelessWidget {
final IconData icon; final String label; final VoidCallback onTap;
const _FeatureChip({required this.icon, required this.label, required this.onTap});
@override
Widget build(BuildContext context) {
return Expanded(
child: GestureDetector(
onTap: onTap,
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 2),
padding: const EdgeInsets.symmetric(vertical: 10),
decoration: BoxDecoration(
gradient: AppColors.bgGradient,
borderRadius: BorderRadius.circular(AppTheme.rSm),
),
child: Column(mainAxisSize: MainAxisSize.min, children: [
Icon(icon, size: 22, color: AppColors.primary),
const SizedBox(height: 4),
Text(label, style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w500, color: AppColors.textPrimary)),
]),
),
),
);
}
}