From 2cb1cf4a9cf20d94d969690d13f4d3804dc40721 Mon Sep 17 00:00:00 2001 From: MingNian <1281442923@qq.com> Date: Wed, 3 Jun 2026 20:23:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=96=B9=E6=B3=95=E7=A7=BB=E5=85=A5=20c?= =?UTF-8?q?lass=20=E5=86=85=E9=83=A8=20+=20=E5=88=A0=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../home/widgets/chat_messages_view.dart | 121 +++++++++--------- 1 file changed, 57 insertions(+), 64 deletions(-) diff --git a/health_app/lib/pages/home/widgets/chat_messages_view.dart b/health_app/lib/pages/home/widgets/chat_messages_view.dart index 2e41bb0..9262e42 100644 --- a/health_app/lib/pages/home/widgets/chat_messages_view.dart +++ b/health_app/lib/pages/home/widgets/chat_messages_view.dart @@ -1160,6 +1160,63 @@ class ChatMessagesView extends ConsumerWidget { _ => (Icons.smart_toy, 'AI 助手', '您的智能健康管家'), }; } + + static ActiveAgent _parseAgentFromName(String? name) { + switch (name) { + case 'consultation': return ActiveAgent.consultation; + case 'health': return ActiveAgent.health; + case 'diet': return ActiveAgent.diet; + case 'medication': return ActiveAgent.medication; + case 'report': return ActiveAgent.report; + case 'exercise': return ActiveAgent.exercise; + default: return ActiveAgent.default_; + } + } + + Widget _buildTaskCardInChat(BuildContext context, WidgetRef ref) { + final health = ref.watch(latestHealthProvider); + return health.when( + data: (data) => _taskCardBubble(data), + loading: () => _taskCardBubble({}), + error: (_, __) => _taskCardBubble({}), + ); + } + + Widget _taskCardBubble(Map data) { + final bp = data['BloodPressure']; + final bpText = bp is Map ? '${bp['systolic'] ?? '--'}/${bp['diastolic'] ?? '--'}' : '--'; + final hr = data['HeartRate']; + final hrText = hr is Map && hr['value'] != null ? '${hr['value']}' : '--'; + final gl = data['Glucose']; + final glText = gl is Map && gl['value'] != null ? '${gl['value']}' : '--'; + final sp = data['SpO2']; + final spText = sp is Map && sp['value'] != null ? '${sp['value']}' : '--'; + + return Container( + margin: const EdgeInsets.only(bottom: 12), + padding: const EdgeInsets.all(14), + decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16), boxShadow: [BoxShadow(color: const Color(0xFF635BFF).withAlpha(10), blurRadius: 8, offset: const Offset(0, 2))]), + child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ + Row(children: [Icon(Icons.today, size: 18, color: const Color(0xFF635BFF)), const SizedBox(width: 8), const Text('今日任务', style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A)))]), + const SizedBox(height: 10), + Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ + _miniMetric('血压', bpText, Icons.favorite), + _miniMetric('心率', hrText, Icons.monitor_heart), + _miniMetric('血糖', glText, Icons.bloodtype), + _miniMetric('血氧', spText, Icons.air), + ]), + ]), + ); + } + + Widget _miniMetric(String label, String value, IconData icon) { + return Column(children: [ + Icon(icon, size: 20, color: const Color(0xFF635BFF)), + const SizedBox(height: 4), + Text(value, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: Color(0xFF1A1A1A))), + Text(label, style: const TextStyle(fontSize: 10, color: Color(0xFF999999))), + ]); + } } // ════════════════════════════════════════════════════════════════ @@ -1258,68 +1315,4 @@ class _ExpandableAdviceState extends State<_ExpandableAdvice> { ); } - static ActiveAgent _parseAgentFromName(String? name) { - switch (name) { - case 'consultation': return ActiveAgent.consultation; - case 'health': return ActiveAgent.health; - case 'diet': return ActiveAgent.diet; - case 'medication': return ActiveAgent.medication; - case 'report': return ActiveAgent.report; - case 'exercise': return ActiveAgent.exercise; - default: return ActiveAgent.default_; - } - } - - Widget _buildTaskCardInChat(BuildContext context, WidgetRef ref) { - final health = ref.watch(latestHealthProvider); - return health.when( - data: (data) => _taskCardBubble(context, ref, data), - loading: () => _taskCardBubble(context, ref, {}), - error: (_, __) => _taskCardBubble(context, ref, {}), - ); - } - - Widget _taskCardBubble(BuildContext context, WidgetRef ref, Map data) { - final bp = data['BloodPressure']; - final bpText = bp is Map ? '${bp['systolic'] ?? '--'}/${bp['diastolic'] ?? '--'}' : '--'; - final hr = data['HeartRate']; - final hrText = hr is Map && hr['value'] != null ? '${hr['value']}' : '--'; - final gl = data['Glucose']; - final glText = gl is Map && gl['value'] != null ? '${gl['value']}' : '--'; - final sp = data['SpO2']; - final spText = sp is Map && sp['value'] != null ? '${sp['value']}' : '--'; - - return Container( - margin: const EdgeInsets.only(bottom: 12), - padding: const EdgeInsets.all(14), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(16), - boxShadow: [BoxShadow(color: const Color(0xFF635BFF).withAlpha(10), blurRadius: 8, offset: const Offset(0, 2))], - ), - child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row(children: [ - Icon(Icons.today, size: 18, color: const Color(0xFF635BFF)), - const SizedBox(width: 8), - const Text('今日任务', style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))), - ]), - const SizedBox(height: 10), - Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - _miniMetric('血压', bpText, Icons.favorite, ref), - _miniMetric('心率', hrText, Icons.monitor_heart, ref), - _miniMetric('血糖', glText, Icons.bloodtype, ref), - _miniMetric('血氧', spText, Icons.air, ref), - ]), - ]), - ); - } - - Widget _miniMetric(String label, String value, IconData icon, WidgetRef ref) { - return Column(children: [ - Icon(icon, size: 20, color: const Color(0xFF635BFF)), - const SizedBox(height: 4), - Text(value, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: Color(0xFF1A1A1A))), - Text(label, style: const TextStyle(fontSize: 10, color: Color(0xFF999999))), - ]); - } }