feat: AI 对话附件上下文解析 + 历史会话归档 + 多页面 UI 重构

- 后端: 新增 AttachmentContextBuilder 解析图片/PDF 摘要并拼入 LLM 上下文; ai_chat_endpoints 扩展附件接口; 新增 ReportAnalysisService
- 前端: 新增历史会话页与 conversation_history_provider; chat 链路支持附件展示与回放
- UI: 重构 medication_checkin / notification_center / profile / health_drawer 等多页面
- 配置: api_client baseUrl 适配当前 WiFi IP
This commit is contained in:
MingNian
2026-07-06 12:44:59 +08:00
parent 4507083f3f
commit 7a93237069
38 changed files with 4165 additions and 1157 deletions

View File

@@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
import '../../core/app_colors.dart';
import '../../core/app_theme.dart';
import '../../core/navigation_provider.dart';
import '../../providers/data_providers.dart';
import '../../services/in_app_notification_service.dart';
@@ -20,6 +21,7 @@ class _NotificationCenterPageState
InAppNotificationHistory? _history;
bool _loading = true;
bool _markingAll = false;
bool _showEarlier = false;
String? _error;
InAppNotificationService get _service =>
@@ -47,12 +49,11 @@ class _NotificationCenterPageState
});
ref.invalidate(notificationUnreadCountProvider);
} catch (error) {
if (mounted) {
setState(() {
_error = '$error';
_loading = false;
});
}
if (!mounted) return;
setState(() {
_error = '$error';
_loading = false;
});
}
}
@@ -146,7 +147,7 @@ class _NotificationCenterPageState
final unread = _history?.unreadCount ?? 0;
return Scaffold(
backgroundColor: Colors.white,
backgroundColor: const Color(0xFFF6F8FC),
appBar: AppBar(
backgroundColor: Colors.white,
elevation: 0,
@@ -160,45 +161,32 @@ class _NotificationCenterPageState
'通知中心',
style: TextStyle(
fontSize: 19,
fontWeight: FontWeight.w700,
fontWeight: FontWeight.w800,
color: AppColors.textPrimary,
),
),
centerTitle: true,
actions: [
if (unread > 0)
Padding(
padding: const EdgeInsets.only(right: 4),
child: TextButton(
onPressed: _markingAll ? null : _markAllRead,
style: TextButton.styleFrom(
foregroundColor: AppColors.textPrimary,
padding: const EdgeInsets.symmetric(horizontal: 10),
),
child: _markingAll
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(
strokeWidth: 2,
color: AppColors.textPrimary,
),
)
: const Text(
'全部已读',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
),
TextButton(
onPressed: _markingAll ? null : _markAllRead,
child: _markingAll
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Text(
'全部已读',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w700,
),
),
),
),
IconButton(
tooltip: '通知设置',
icon: const Icon(
Icons.settings_outlined,
color: AppColors.textPrimary,
),
icon: const Icon(Icons.settings_outlined),
onPressed: () => pushRoute(ref, 'notificationPrefs'),
),
const SizedBox(width: 4),
@@ -206,16 +194,14 @@ class _NotificationCenterPageState
),
body: RefreshIndicator(
onRefresh: _load,
color: const Color(0xFF6366F1),
color: AppColors.primary,
child: _buildBody(items, unread),
),
);
}
Widget _buildBody(List<InAppNotification> items, int unread) {
if (_loading) {
return const Center(child: CircularProgressIndicator());
}
if (_loading) return const Center(child: CircularProgressIndicator());
if (_error != null) {
return _MessageState(
icon: LucideIcons.wifiOff,
@@ -250,7 +236,6 @@ class _NotificationCenterPageState
padding: const EdgeInsets.fromLTRB(16, 14, 16, 32),
children: [
if (unread > 0) _UnreadHint(unreadCount: unread),
const SizedBox(height: 8),
if (today.isNotEmpty) ...[
const _SectionTitle('今天'),
const SizedBox(height: 10),
@@ -258,9 +243,14 @@ class _NotificationCenterPageState
],
if (earlier.isNotEmpty) ...[
if (today.isNotEmpty) const SizedBox(height: 18),
const _SectionTitle('更早'),
_CollapsibleSectionTitle(
text: '更早',
count: earlier.length,
expanded: _showEarlier,
onTap: () => setState(() => _showEarlier = !_showEarlier),
),
const SizedBox(height: 10),
...earlier.map(_buildDismissible),
if (_showEarlier) ...earlier.map(_buildDismissible),
],
],
);
@@ -275,12 +265,8 @@ class _NotificationCenterPageState
alignment: Alignment.centerRight,
padding: const EdgeInsets.only(right: 26),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [AppColors.error.withValues(alpha: 0.6), AppColors.error],
),
borderRadius: BorderRadius.circular(28),
color: AppColors.error,
borderRadius: BorderRadius.circular(16),
),
child: const Row(
mainAxisSize: MainAxisSize.min,
@@ -292,106 +278,157 @@ class _NotificationCenterPageState
style: TextStyle(
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.w600,
fontWeight: FontWeight.w700,
),
),
],
),
),
onDismissed: (_) => _delete(item),
child: _NotificationCard(item: item, onTap: () => _open(item)),
child: SizedBox(
height: 98,
child: _NotificationCard(item: item, onTap: () => _open(item)),
),
),
);
}
/// 顶部一行精致提示——只在有未读时显示,不抢眼
class _UnreadHint extends StatelessWidget {
final int unreadCount;
const _UnreadHint({required this.unreadCount});
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.fromLTRB(0, 4, 0, 12),
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
decoration: BoxDecoration(
color: const Color(0xFFFFFBEB),
borderRadius: BorderRadius.circular(999),
border: Border.all(color: const Color(0xFFFDE68A)),
),
child: Row(
children: [
Container(
width: 8,
height: 8,
decoration: const BoxDecoration(
color: Color(0xFFF97316),
shape: BoxShape.circle,
),
Widget build(BuildContext context) => Container(
margin: const EdgeInsets.fromLTRB(0, 2, 0, 14),
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 11),
decoration: BoxDecoration(
color: const Color(0xFFFFFBEB),
borderRadius: BorderRadius.circular(14),
border: Border.all(color: const Color(0xFFFDE68A)),
),
child: Row(
children: [
const Icon(LucideIcons.bellRing, size: 18, color: Color(0xFFF97316)),
const SizedBox(width: 9),
Text(
'你有 $unreadCount 条未读消息',
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w800,
color: Color(0xFF92400E),
),
const SizedBox(width: 8),
Text(
'你有 $unreadCount 条未读消息',
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w800,
color: Color(0xFF92400E),
),
),
],
),
);
}
),
],
),
);
}
class _SectionTitle extends StatelessWidget {
final String text;
const _SectionTitle(this.text);
@override
Widget build(BuildContext context) => Container(
margin: const EdgeInsets.fromLTRB(0, 12, 0, 2),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: const Color(0xFFF8FAFC),
borderRadius: BorderRadius.circular(999),
border: Border.all(color: const Color(0xFFE5E7EB)),
),
Widget build(BuildContext context) => _SectionShell(
child: Row(
children: [
Container(
width: 8,
height: 8,
decoration: BoxDecoration(
gradient: AppColors.doctorGradient,
borderRadius: BorderRadius.circular(99),
),
const Icon(
LucideIcons.calendarDays,
size: 18,
color: AppColors.primary,
),
const SizedBox(width: 8),
Text(
text,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w800,
fontWeight: FontWeight.w900,
color: AppColors.textPrimary,
),
),
const SizedBox(width: 10),
Expanded(
child: Container(
height: 1,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
const Color(0xFFE5E7EB),
const Color(0xFFE5E7EB).withValues(alpha: 0),
],
),
),
),
],
),
);
}
class _SectionShell extends StatelessWidget {
final Widget child;
const _SectionShell({required this.child});
@override
Widget build(BuildContext context) => Container(
margin: const EdgeInsets.fromLTRB(0, 6, 0, 2),
padding: const EdgeInsets.symmetric(horizontal: 13, vertical: 10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(14),
border: Border.all(color: AppColors.borderLight),
boxShadow: [
BoxShadow(
color: const Color(0xFF101828).withValues(alpha: 0.035),
blurRadius: 10,
offset: const Offset(0, 4),
),
],
),
child: child,
);
}
class _CollapsibleSectionTitle extends StatelessWidget {
final String text;
final int count;
final bool expanded;
final VoidCallback onTap;
const _CollapsibleSectionTitle({
required this.text,
required this.count,
required this.expanded,
required this.onTap,
});
@override
Widget build(BuildContext context) => GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
child: _SectionShell(
child: Row(
children: [
const Icon(
LucideIcons.history,
size: 18,
color: AppColors.textSecondary,
),
const SizedBox(width: 8),
Text(
'$text · $count',
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w900,
color: AppColors.textPrimary,
),
),
const Spacer(),
Text(
expanded ? '收起' : '展开',
style: const TextStyle(
fontSize: 13,
fontWeight: FontWeight.w800,
color: AppColors.textSecondary,
),
),
const SizedBox(width: 8),
Icon(
expanded ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down,
size: 22,
color: AppColors.textSecondary,
),
],
),
),
);
}
@@ -406,80 +443,113 @@ class _NotificationCard extends StatelessWidget {
final visual = _NotificationVisual.of(item);
return Material(
color: Colors.white,
borderRadius: BorderRadius.circular(28),
elevation: 0,
borderRadius: BorderRadius.circular(16),
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(28),
borderRadius: BorderRadius.circular(16),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
height: 98,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(28),
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: item.isRead
? const Color(0xFFF1F5F9)
: visual.color.withValues(alpha: 0.24),
width: 1,
? AppColors.borderLight
: visual.color.withValues(alpha: 0.32),
width: 1.1,
),
boxShadow: [
BoxShadow(
color: const Color(0xFF0F172A).withValues(alpha: 0.08),
blurRadius: 22,
offset: const Offset(0, 10),
),
BoxShadow(
color: visual.color.withValues(alpha: item.isRead ? 0 : 0.08),
blurRadius: 18,
offset: const Offset(0, 8),
),
],
boxShadow: [AppTheme.shadowLight],
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
child: Stack(
children: [
// 图标
Stack(
clipBehavior: Clip.none,
children: [
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: visual.lightColor,
borderRadius: BorderRadius.circular(18),
border: Border.all(
color: visual.color.withValues(alpha: 0.12),
),
),
child: Icon(visual.icon, size: 23, color: visual.color),
),
if (!item.isRead)
Positioned(
top: -2,
right: -2,
child: Container(
width: 10,
height: 10,
decoration: BoxDecoration(
color: const Color(0xFFEF4444),
shape: BoxShape.circle,
border: Border.all(color: Colors.white, width: 1.5),
),
),
),
],
),
const SizedBox(width: 13),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
Padding(
padding: const EdgeInsets.fromLTRB(14, 13, 12, 13),
child: Row(
children: [
Row(
Stack(
clipBehavior: Clip.none,
children: [
Expanded(
child: Text(
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
visual.color.withValues(alpha: 0.18),
visual.lightColor,
],
),
borderRadius: BorderRadius.circular(14),
border: Border.all(
color: visual.color.withValues(alpha: 0.22),
),
),
child: Icon(
visual.icon,
size: 24,
color: visual.color,
),
),
if (!item.isRead)
Positioned(
top: -2,
right: -2,
child: Container(
width: 10,
height: 10,
decoration: BoxDecoration(
color: AppColors.error,
shape: BoxShape.circle,
border: Border.all(
color: Colors.white,
width: 1.5,
),
),
),
),
],
),
const SizedBox(width: 13),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
Container(
padding: const EdgeInsets.symmetric(
horizontal: 7,
vertical: 3,
),
decoration: BoxDecoration(
color: visual.lightColor,
borderRadius: BorderRadius.circular(999),
),
child: Text(
visual.label,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w800,
color: visual.color,
),
),
),
const SizedBox(width: 8),
Text(
_formatTime(item.createdAt),
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.w700,
color: AppColors.textHint,
),
),
],
),
const SizedBox(height: 5),
Text(
item.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
@@ -489,54 +559,35 @@ class _NotificationCard extends StatelessWidget {
? FontWeight.w700
: FontWeight.w800,
color: AppColors.textPrimary,
height: 1.3,
height: 1.2,
),
),
),
const SizedBox(width: 8),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
decoration: BoxDecoration(
color: const Color(0xFFF8FAFC),
borderRadius: BorderRadius.circular(999),
),
child: Text(
_formatTime(item.createdAt),
const SizedBox(height: 4),
Text(
item.message,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 11,
fontWeight: FontWeight.w700,
fontSize: 14,
height: 1.25,
fontWeight: FontWeight.w500,
color: AppColors.textSecondary,
),
),
),
],
),
const SizedBox(height: 6),
Text(
item.message,
maxLines: 2,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 14,
height: 1.5,
fontWeight: FontWeight.w500,
color: AppColors.textSecondary,
],
),
),
if (item.actionType != null) ...[
const SizedBox(width: 6),
const Icon(
Icons.chevron_right_rounded,
size: 22,
color: AppColors.textSecondary,
),
],
],
),
),
if (item.actionType != null) ...[
const SizedBox(width: 4),
const Icon(
Icons.chevron_right_rounded,
size: 22,
color: AppColors.textSecondary,
),
],
],
),
),
@@ -555,8 +606,8 @@ class _NotificationCard extends StatelessWidget {
local.day == now.day) {
return time;
}
if (local.year == now.year) return '${local.month}${local.day} $time';
return '${local.year}${local.month}${local.day} $time';
if (local.year == now.year) return '${local.month}/${local.day} $time';
return '${local.year}/${local.month}/${local.day} $time';
}
}
@@ -573,40 +624,38 @@ class _NotificationVisual {
case 'exercise':
return const _NotificationVisual(
LucideIcons.activity,
Color(0xFF60A5FA),
Color(0xFFEFF6FF),
Color(0xFF16A34A),
Color(0xFFEAF8EF),
'运动',
);
case 'health':
if (item.severity == 'critical') {
return const _NotificationVisual(
LucideIcons.triangleAlert,
Color(0xFFEF4444),
Color(0xFFFEE2E2),
'紧急',
);
}
return const _NotificationVisual(
LucideIcons.heartPulse,
Color(0xFFF59E0B),
Color(0xFFFEF3C7),
'健康',
);
return item.severity == 'critical'
? const _NotificationVisual(
LucideIcons.triangleAlert,
Color(0xFFEF4444),
Color(0xFFFEE2E2),
'紧急',
)
: const _NotificationVisual(
LucideIcons.heartPulse,
Color(0xFFF59E0B),
Color(0xFFFEF3C7),
'健康',
);
case 'report':
if (item.severity == 'error') {
return const _NotificationVisual(
LucideIcons.fileWarning,
Color(0xFFEF4444),
Color(0xFFFEE2E2),
'报告',
);
}
return const _NotificationVisual(
LucideIcons.fileCheck2,
Color(0xFF8B5CF6),
Color(0xFFEDE9FE),
'报告',
);
return item.severity == 'error'
? const _NotificationVisual(
LucideIcons.fileWarning,
Color(0xFFEF4444),
Color(0xFFFEE2E2),
'报告',
)
: const _NotificationVisual(
LucideIcons.fileCheck2,
Color(0xFF8B5CF6),
Color(0xFFEDE9FE),
'报告',
);
default:
return const _NotificationVisual(
LucideIcons.pill,
@@ -642,15 +691,9 @@ class _MessageState extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 36),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(24),
border: Border.all(color: const Color(0xFFE9EEF5)),
boxShadow: [
BoxShadow(
color: const Color(0xFF101828).withValues(alpha: 0.04),
blurRadius: 14,
offset: const Offset(0, 4),
),
],
borderRadius: BorderRadius.circular(16),
border: Border.all(color: AppColors.borderLight),
boxShadow: [AppTheme.shadowLight],
),
child: Column(
children: [
@@ -658,14 +701,10 @@ class _MessageState extends StatelessWidget {
width: 72,
height: 72,
decoration: BoxDecoration(
gradient: const LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color(0xFFEEF2FF), Color(0xFFF5F3FF)],
),
borderRadius: BorderRadius.circular(22),
color: AppColors.primaryLight,
borderRadius: BorderRadius.circular(18),
),
child: Icon(icon, size: 32, color: const Color(0xFF6366F1)),
child: Icon(icon, size: 32, color: AppColors.primary),
),
const SizedBox(height: 20),
Text(
@@ -681,7 +720,7 @@ class _MessageState extends StatelessWidget {
message,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 13,
fontSize: 14,
height: 1.5,
color: AppColors.textSecondary,
),
@@ -691,7 +730,7 @@ class _MessageState extends StatelessWidget {
FilledButton(
onPressed: onPressed,
style: FilledButton.styleFrom(
backgroundColor: const Color(0xFF6366F1),
backgroundColor: AppColors.primary,
padding: const EdgeInsets.symmetric(
horizontal: 28,
vertical: 12,