- 全新"朝露"主题:深青绿主色(#2D6A4F),暖白底,完整设计Token - 引入 shadcn_ui 组件库,MaterialApp 注入 ShadTheme - 新增 4 个公共组件:AppCard、AppMenuItem、AppEmptyState、AppTabChip - 全面消除硬编码颜色,统一使用 AppTheme Token - 全局字号 +3~4pt,图标等比放大 +3px - home/medication/profile/settings/login 等核心页面重写 - 路由和功能逻辑零改动
241 lines
10 KiB
Dart
241 lines
10 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../core/app_theme.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../../core/navigation_provider.dart';
|
|
import 'report_pages.dart';
|
|
|
|
/// AI 解读页 — 从服务器获取真实报告数据
|
|
class AiAnalysisPage extends ConsumerStatefulWidget {
|
|
final String id;
|
|
const AiAnalysisPage({super.key, required this.id});
|
|
|
|
@override
|
|
ConsumerState<AiAnalysisPage> createState() => _AiAnalysisPageState();
|
|
}
|
|
|
|
class _AiAnalysisPageState extends ConsumerState<AiAnalysisPage> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
ref.read(reportProvider.notifier).loadReports();
|
|
ref.read(reportProvider.notifier).fetchReportDetail(widget.id);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final analysis = ref.watch(reportProvider.select((s) => s.currentAnalysis));
|
|
final reports = ref.watch(reportProvider.select((s) => s.reports));
|
|
final reportItem = reports.where((r) => r.id == widget.id).firstOrNull;
|
|
|
|
if (analysis == null) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('AI 解读')),
|
|
body: const Center(child: CircularProgressIndicator(color: AppTheme.primary)),
|
|
);
|
|
}
|
|
|
|
return Scaffold(
|
|
backgroundColor: AppTheme.bg,
|
|
appBar: AppBar(
|
|
title: const Text('AI 智能解读'),
|
|
leading: IconButton(
|
|
icon: const Icon(Icons.arrow_back),
|
|
onPressed: () {
|
|
ref.read(reportProvider.notifier).clearAnalysis();
|
|
popRoute(ref);
|
|
},
|
|
),
|
|
),
|
|
body: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
// 报告标题
|
|
_buildHeader(analysis),
|
|
const SizedBox(height: 16),
|
|
// 审核状态
|
|
if (reportItem != null) _buildStatusBadge(reportItem),
|
|
if (reportItem != null) const SizedBox(height: 16),
|
|
// 指标分析
|
|
_buildIndicators(analysis),
|
|
const SizedBox(height: 16),
|
|
// AI 总结
|
|
_buildSummary(analysis),
|
|
const SizedBox(height: 16),
|
|
// 医生审核意见
|
|
if (reportItem != null && reportItem.status == 'DoctorReviewed')
|
|
_buildDoctorReview(reportItem),
|
|
]),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildHeader(ReportAnalysis analysis) {
|
|
return Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [BoxShadow(color: AppTheme.primary.withAlpha(10), blurRadius: 8)]),
|
|
child: Row(children: [
|
|
Container(width: 48, height: 48, decoration: BoxDecoration(color: AppTheme.primaryLight, borderRadius: BorderRadius.circular(12)),
|
|
child: const Icon(Icons.auto_awesome, size: 28, color: AppTheme.primary)),
|
|
const SizedBox(width: 14),
|
|
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Text(analysis.reportType, style: const TextStyle(fontSize: 21, fontWeight: FontWeight.w700)),
|
|
const SizedBox(height: 4),
|
|
const Text('AI 预解读结果 · 待医生确认', style: TextStyle(fontSize: 16, color: Color(0xFF999999))),
|
|
])),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildStatusBadge(ReportItem report) {
|
|
final isReviewed = report.status == 'DoctorReviewed';
|
|
return Container(
|
|
width: double.infinity, padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: isReviewed ? const Color(0xFFDCFCE7) : const Color(0xFFFFF3E0),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: Row(mainAxisSize: MainAxisSize.min, children: [
|
|
Icon(isReviewed ? Icons.check_circle : Icons.hourglass_empty, size: 21,
|
|
color: isReviewed ? AppTheme.success : const Color(0xFFF59E0B)),
|
|
const SizedBox(width: 8),
|
|
Text(isReviewed ? '已通过医生审核' : '等待医生审核中',
|
|
style: TextStyle(fontSize: 17, fontWeight: FontWeight.w500,
|
|
color: isReviewed ? AppTheme.success : const Color(0xFFF59E0B))),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildIndicators(ReportAnalysis analysis) {
|
|
return Container(
|
|
width: double.infinity,
|
|
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16)),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
const Padding(
|
|
padding: EdgeInsets.fromLTRB(16, 16, 16, 8),
|
|
child: Text('指标分析', style: TextStyle(fontSize: 19, fontWeight: FontWeight.w700)),
|
|
),
|
|
...analysis.indicators.map((ind) => _buildIndicatorRow(ind)),
|
|
const SizedBox(height: 8),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildIndicatorRow(Indicator ind) {
|
|
final Color color;
|
|
final IconData icon;
|
|
switch (ind.status) {
|
|
case 'high': color = AppTheme.error; icon = Icons.arrow_upward; break;
|
|
case 'low': color = const Color(0xFFF9A825); icon = Icons.arrow_downward; break;
|
|
default: color = AppTheme.success; icon = Icons.check_circle;
|
|
}
|
|
return Container(
|
|
margin: const EdgeInsets.symmetric(horizontal: 16),
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
decoration: const BoxDecoration(border: Border(bottom: BorderSide(color: Color(0xFFF0F0F0)))),
|
|
child: Row(children: [
|
|
Expanded(
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Text(ind.name, style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w500)),
|
|
if (ind.referenceRange != null && ind.referenceRange!.isNotEmpty)
|
|
Text('参考值: ${ind.referenceRange}', style: const TextStyle(fontSize: 15, color: Color(0xFF999999))),
|
|
]),
|
|
),
|
|
Column(crossAxisAlignment: CrossAxisAlignment.end, children: [
|
|
Text('${ind.value} ${ind.unit}',
|
|
style: TextStyle(fontSize: 19, fontWeight: FontWeight.w600, color: color)),
|
|
Icon(icon, size: 17, color: color),
|
|
]),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildSummary(ReportAnalysis analysis) {
|
|
return Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(color: const Color(0xFFFEFCE8), borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: const Color(0xFFFDE68A))),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
const Row(children: [
|
|
Text('💡', style: TextStyle(fontSize: 21)),
|
|
SizedBox(width: 8),
|
|
Text('综合解读', style: TextStyle(fontSize: 19, fontWeight: FontWeight.w700, color: Color(0xFFD97706))),
|
|
]),
|
|
const SizedBox(height: 10),
|
|
Text(analysis.summary.isNotEmpty ? analysis.summary : '暂无 AI 解读结果',
|
|
style: const TextStyle(fontSize: 17, color: Color(0xFF92400E), height: 1.6)),
|
|
const SizedBox(height: 10),
|
|
Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(10),
|
|
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10)),
|
|
child: const Text('⚠️ AI 解读仅供参考,请以医生诊断为准',
|
|
style: TextStyle(fontSize: 15, color: Color(0xFFD97706))),
|
|
),
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _buildDoctorReview(ReportItem report) {
|
|
return Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(color: const Color(0xFFDCFCE7), borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: const Color(0xFF86EFAC))),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
const Row(children: [
|
|
Text('✅', style: TextStyle(fontSize: 21)),
|
|
SizedBox(width: 8),
|
|
Text('医生审核意见', style: TextStyle(fontSize: 19, fontWeight: FontWeight.w700, color: Color(0xFF2E7D32))),
|
|
]),
|
|
if (report.doctorName != null) ...[
|
|
const SizedBox(height: 4),
|
|
Text('审核医生:${report.doctorName}', style: const TextStyle(fontSize: 16, color: Color(0xFF4CAF50))),
|
|
],
|
|
if (report.reviewedAt != null) ...[
|
|
const SizedBox(height: 2),
|
|
Text('审核时间:${report.reviewedAt!.toLocal().toString().substring(0, 16)}',
|
|
style: const TextStyle(fontSize: 15, color: Color(0xFF81C784))),
|
|
],
|
|
if (report.severity != null) ...[
|
|
const SizedBox(height: 8),
|
|
_severityBadge(report.severity!),
|
|
],
|
|
if (report.doctorComment != null && report.doctorComment!.isNotEmpty) ...[
|
|
const SizedBox(height: 10),
|
|
Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10)),
|
|
child: Text('💬 ${report.doctorComment!}',
|
|
style: const TextStyle(fontSize: 18, color: Color(0xFF1A1A1A), height: 1.5)),
|
|
),
|
|
],
|
|
if (report.doctorRecommendation != null && report.doctorRecommendation!.isNotEmpty) ...[
|
|
const SizedBox(height: 8),
|
|
Container(
|
|
width: double.infinity, padding: const EdgeInsets.all(12),
|
|
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10)),
|
|
child: Text('📝 ${report.doctorRecommendation!}',
|
|
style: const TextStyle(fontSize: 17, color: Color(0xFF333333), height: 1.5)),
|
|
),
|
|
],
|
|
]),
|
|
);
|
|
}
|
|
|
|
Widget _severityBadge(String severity) {
|
|
final (label, color, bg) = switch (severity) {
|
|
'Normal' => ('🟢 正常', AppTheme.success, const Color(0xFFDCFCE7)),
|
|
'Abnormal' => ('🟡 轻度异常', const Color(0xFFF59E0B), const Color(0xFFFFF3E0)),
|
|
'Severe' => ('🟠 中度异常', const Color(0xFFFF7043), const Color(0xFFFEE2E2)),
|
|
'Critical' => ('🔴 重度异常', const Color(0xFFDC2626), const Color(0xFFFEE2E2)),
|
|
_ => (severity, Colors.grey, Colors.grey.withAlpha(30)),
|
|
};
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
|
decoration: BoxDecoration(color: bg, borderRadius: BorderRadius.circular(6)),
|
|
child: Text(label, style: TextStyle(fontSize: 15, fontWeight: FontWeight.w500, color: color)),
|
|
);
|
|
}
|
|
}
|