fix: 方法移入 class 内部 + 删重复代码
This commit is contained in:
@@ -1160,6 +1160,63 @@ class ChatMessagesView extends ConsumerWidget {
|
|||||||
_ => (Icons.smart_toy, 'AI 助手', '您的智能健康管家'),
|
_ => (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<String, dynamic> 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<String, dynamic> 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))),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user