【后端修复】 - 删除diet/consultation agent假工具声明 - 修复DayOfWeek实体注释 - 修复Vision API content序列化 - cleanup_service级联删除修复 - 用药提醒时区偏差修复 - 统一DateTime处理(UtcNow+8) - 新增UTC DateTime JSON转换器 【前端UI重构】 - 配色体系全面更新(#8B5CF6淡紫+#F0ECFF背景) - 登录页重设计 - 首页重设计(透明顶栏、渐变背景、胶囊输入区) - 聊天卡片加白蓝边框、渐变标题 - 侧边栏重构(渐变背景、合并顶部、删除底部设置) - 确认卡片可编辑字段恢复 - 所有子页面加返回按钮 - catch异常加日志 - 删除后refresh provider缓存
303 lines
13 KiB
Dart
303 lines
13 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.bgGradient),
|
|
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),
|
|
),
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
|
child: const Text('服务包', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: Colors.white)),
|
|
),
|
|
),
|
|
const ServicePackageCard(compact: true),
|
|
]),
|
|
),
|
|
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.textPrimary),
|
|
const SizedBox(height: 2),
|
|
const Text('设置', style: TextStyle(fontSize: 11, color: AppColors.textPrimary)),
|
|
]),
|
|
),
|
|
),
|
|
),
|
|
]),
|
|
),
|
|
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(
|
|
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),
|
|
),
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
|
child: const Row(mainAxisSize: MainAxisSize.min, children: [
|
|
Icon(Icons.monitor_heart_rounded, size: 15, color: Colors.white),
|
|
SizedBox(width: 4),
|
|
Text('健康概览', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, 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),
|
|
),
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
|
child: const Text('功能', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, 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)),
|
|
]),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|