- 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,支持局域网访问
120 lines
5.9 KiB
Dart
120 lines
5.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../core/navigation_provider.dart';
|
|
import '../providers/auth_provider.dart';
|
|
import '../providers/data_providers.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(
|
|
child: SafeArea(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// 用户信息
|
|
Container(
|
|
padding: const EdgeInsets.all(20),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () => pushRoute(ref, 'profile'),
|
|
child: CircleAvatar(
|
|
radius: 28,
|
|
backgroundColor: const Color(0xFFEDEBFF),
|
|
child: Icon(Icons.person, size: 32, color: Theme.of(context).colorScheme.primary),
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
Text(user?.name ?? '未设置昵称', style: Theme.of(context).textTheme.titleMedium),
|
|
if (user != null) const SizedBox(height: 4),
|
|
Text(user?.phone ?? '', style: Theme.of(context).textTheme.labelMedium),
|
|
],
|
|
),
|
|
),
|
|
_DrawerItem(icon: Icons.settings, label: '设置', onTap: () => pushRoute(ref, 'settings')),
|
|
const Divider(),
|
|
|
|
// 健康概览——接真实数据
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
|
child: Text('健康概览', style: Theme.of(context).textTheme.labelMedium!.copyWith(fontWeight: FontWeight.w600)),
|
|
),
|
|
latestHealth.when(
|
|
data: (data) => Column(children: [
|
|
_HealthMetric(icon: Icons.favorite, label: '血压', value: _bpText(data['BloodPressure']), onTap: () => pushRoute(ref, 'trend', params: {'type': 'blood_pressure'})),
|
|
_HealthMetric(icon: Icons.monitor_heart, label: '心率', value: _metricText(data['HeartRate'], '次/分'), onTap: () => pushRoute(ref, 'trend', params: {'type': 'heart_rate'})),
|
|
_HealthMetric(icon: Icons.bloodtype, label: '血糖', value: _metricText(data['Glucose'], 'mmol/L'), onTap: () => pushRoute(ref, 'trend', params: {'type': 'glucose'})),
|
|
_HealthMetric(icon: Icons.air, label: '血氧', value: _metricText(data['SpO2'], '%'), onTap: () => pushRoute(ref, 'trend', params: {'type': 'spo2'})),
|
|
]),
|
|
loading: () => const Padding(padding: EdgeInsets.all(16), child: Center(child: SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2)))),
|
|
error: (_, _) => Column(children: [
|
|
_HealthMetric(icon: Icons.favorite, label: '血压', value: '--'),
|
|
_HealthMetric(icon: Icons.monitor_heart, label: '心率', value: '--'),
|
|
_HealthMetric(icon: Icons.bloodtype, label: '血糖', value: '--'),
|
|
_HealthMetric(icon: Icons.air, label: '血氧', value: '--'),
|
|
]),
|
|
),
|
|
|
|
const Divider(),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
|
child: Text('历史对话', style: Theme.of(context).textTheme.labelMedium!.copyWith(fontWeight: FontWeight.w600)),
|
|
),
|
|
const Expanded(child: Center(child: Text('暂无历史对话', style: TextStyle(color: Color(0xFF999999), fontSize: 14)))),
|
|
|
|
const Divider(),
|
|
_DrawerItem(icon: Icons.logout, label: '退出登录', 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'); }
|
|
}),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
String _bpText(dynamic bp) {
|
|
if (bp == null) return '--';
|
|
if (bp is Map) return '${bp['systolic'] ?? '--'}/${bp['diastolic'] ?? '--'}';
|
|
return '--';
|
|
}
|
|
|
|
String _metricText(dynamic metric, String unit) {
|
|
if (metric == null) return '--';
|
|
if (metric is Map) {
|
|
final v = metric['value'];
|
|
return v != null ? '$v $unit' : '--';
|
|
}
|
|
return '--';
|
|
}
|
|
}
|
|
|
|
class _DrawerItem extends StatelessWidget {
|
|
final IconData icon; final String label; final VoidCallback onTap;
|
|
const _DrawerItem({required this.icon, required this.label, required this.onTap});
|
|
@override Widget build(BuildContext context) => ListTile(leading: Icon(icon, size: 20, color: const Color(0xFF666666)), title: Text(label, style: const TextStyle(fontSize: 16)), onTap: onTap, dense: true);
|
|
}
|
|
|
|
class _HealthMetric extends StatelessWidget {
|
|
final IconData icon; final String label; final String value; final VoidCallback? onTap;
|
|
const _HealthMetric({required this.icon, required this.label, required this.value, this.onTap});
|
|
@override Widget build(BuildContext context) => ListTile(
|
|
leading: Icon(icon, size: 18, color: const Color(0xFF635BFF)),
|
|
title: Text(label, style: const TextStyle(fontSize: 16, color: Color(0xFF1A1A1A))),
|
|
trailing: Text(value, style: TextStyle(fontSize: 16, color: value == '--' ? const Color(0xFF999999) : const Color(0xFF1A1A1A))),
|
|
dense: true,
|
|
onTap: onTap,
|
|
);
|
|
}
|