refactor: 死代码清理 + 趋势图重构 + 侧边栏交互优化 + 智能体卡片去延迟
- 死代码清理: 删除 AppCard/AppMenuItem/AppTabChip/AppButtons 等 4 个未使用 Widget 文件; 清理 common_widgets/enterprise_widgets/app_status_badge 中未使用 class; 移除 HealthService 等未使用方法; 后端移除 ExerciseService.CreateFromItemsAsync/HealthArchiveService.GetOrCreateAsync/MedicationAgentHandler 死分支/ChatRequest DTO - 趋势图: 直线折线 + 渐变填充 + 阴影; 去网格; X 轴日+月份; Y 轴整数刻度最多 4 个; 点击数据点/录入记录显示上方浮层; 选中点变实心 - 侧边栏: 对话记录改单选删除(灰底高亮); 操作栏浮层修复触摸问题; 常用功能/健康仪表盘间距收紧; _Panel 去外框 - 智能体: 欢迎卡片去掉 400ms 延迟; 胶囊去阴影 - 其他: api_client IP 适配; 多页面 UI 微调; 新增 chat_provider/prelaunch_guardrails 测试
This commit is contained in:
@@ -78,7 +78,7 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
final imagePath = _pickedImagePath;
|
||||
if (text.isEmpty && imagePath == null) return;
|
||||
_textCtrl.clear();
|
||||
_focusNode.unfocus();
|
||||
_dismissKeyboard();
|
||||
setState(() => _pickedImagePath = null);
|
||||
if (imagePath != null) {
|
||||
ref.read(chatProvider.notifier).sendImage(imagePath, text);
|
||||
@@ -145,9 +145,9 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
left: 0,
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
width: 44,
|
||||
width: MediaQuery.sizeOf(context).width * 0.8,
|
||||
child: GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
behavior: HitTestBehavior.translucent,
|
||||
onHorizontalDragStart: (details) {
|
||||
_drawerDragStartX = details.globalPosition.dx;
|
||||
},
|
||||
@@ -255,16 +255,20 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
];
|
||||
|
||||
Widget _buildAgentBar() {
|
||||
final activeAgent = ref.watch(
|
||||
chatProvider.select((state) => state.activeAgent),
|
||||
);
|
||||
return SizedBox(
|
||||
height: 42,
|
||||
height: 46,
|
||||
child: ListView.separated(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 2),
|
||||
itemCount: _agentDefs.length,
|
||||
separatorBuilder: (_, _) => const SizedBox(width: 8),
|
||||
itemBuilder: (_, i) {
|
||||
final agent = _agentDefs[i];
|
||||
final visual = _agentVisual(agent);
|
||||
final selected = activeAgent == agent;
|
||||
return GestureDetector(
|
||||
onTap: () => ref
|
||||
.read(chatProvider.notifier)
|
||||
@@ -272,9 +276,14 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 13, vertical: 9),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.86),
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(999),
|
||||
border: Border.all(color: Colors.white, width: 1.2),
|
||||
border: Border.all(
|
||||
color: selected
|
||||
? AppColors.auraIndigo.withValues(alpha: 0.42)
|
||||
: const Color(0xFFD5DAE4),
|
||||
width: selected ? 1.4 : 1.1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -477,6 +486,7 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
}
|
||||
|
||||
void _showAttachmentPicker(BuildContext context) {
|
||||
_dismissKeyboard();
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
backgroundColor: Colors.white,
|
||||
@@ -496,6 +506,7 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
title: const Text('拍照'),
|
||||
onTap: () {
|
||||
Navigator.pop(ctx);
|
||||
_dismissKeyboard();
|
||||
_pickImage(ImageSource.camera);
|
||||
},
|
||||
),
|
||||
@@ -507,6 +518,7 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
title: const Text('从相册选择'),
|
||||
onTap: () {
|
||||
Navigator.pop(ctx);
|
||||
_dismissKeyboard();
|
||||
_pickImage(ImageSource.gallery);
|
||||
},
|
||||
),
|
||||
@@ -518,6 +530,7 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
title: const Text('上传 PDF'),
|
||||
onTap: () async {
|
||||
Navigator.pop(ctx);
|
||||
_dismissKeyboard();
|
||||
final result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.custom,
|
||||
allowedExtensions: ['pdf'],
|
||||
@@ -532,6 +545,7 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
.read(chatProvider.notifier)
|
||||
.sendPdf(path, pdfFile.name, _textCtrl.text.trim());
|
||||
_textCtrl.clear();
|
||||
_dismissKeyboard();
|
||||
if (mounted) setState(() {});
|
||||
},
|
||||
),
|
||||
@@ -543,17 +557,25 @@ class _HomePageState extends ConsumerState<HomePage>
|
||||
}
|
||||
|
||||
Future<void> _pickImage(ImageSource source) async {
|
||||
_dismissKeyboard();
|
||||
final picked = await ImagePicker().pickImage(
|
||||
source: source,
|
||||
imageQuality: 85,
|
||||
);
|
||||
_dismissKeyboard();
|
||||
if (picked != null) {
|
||||
final token = await ref.read(apiClientProvider).accessToken;
|
||||
if (token == null) return;
|
||||
setState(() => _pickedImagePath = picked.path);
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => _dismissKeyboard());
|
||||
}
|
||||
}
|
||||
|
||||
void _dismissKeyboard() {
|
||||
_focusNode.unfocus();
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
}
|
||||
|
||||
Future<void> _pickFoodImage(ImageSource source) async {
|
||||
final picked = await ImagePicker().pickImage(
|
||||
source: source,
|
||||
|
||||
@@ -859,13 +859,13 @@ class ChatMessagesView extends ConsumerWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
child: msg.confirmed
|
||||
child: msg.confirmed || msg.isReadOnly
|
||||
? Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: AppColors.successButtonGradient,
|
||||
borderRadius: BorderRadius.circular(18),
|
||||
),
|
||||
child: const Row(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
@@ -873,10 +873,10 @@ class ChatMessagesView extends ConsumerWidget {
|
||||
size: 22,
|
||||
color: Colors.white,
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'录入成功',
|
||||
style: TextStyle(
|
||||
msg.isReadOnly ? '历史记录' : '录入成功',
|
||||
style: const TextStyle(
|
||||
fontSize: 19,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.white,
|
||||
@@ -1236,9 +1236,7 @@ class ChatMessagesView extends ConsumerWidget {
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: InteractiveViewer(
|
||||
child: path.startsWith('http')
|
||||
? Image.network(resolvedPath, fit: BoxFit.contain)
|
||||
: resolvedPath.startsWith('http')
|
||||
child: resolvedPath.startsWith('http')
|
||||
? Image.network(resolvedPath, fit: BoxFit.contain)
|
||||
: Image.file(File(resolvedPath), fit: BoxFit.contain),
|
||||
),
|
||||
@@ -1270,20 +1268,6 @@ class ChatMessagesView extends ConsumerWidget {
|
||||
return path;
|
||||
}
|
||||
|
||||
/// 清理 AI 返回文本中的异常占位符(Markdown 格式交给 MarkdownBody 渲染)
|
||||
// ignore: unused_element
|
||||
static String _cleanAiText(String text) {
|
||||
var t = text;
|
||||
// 移除 $1、$2 等占位符
|
||||
t = t.replaceAll(RegExp(r'\$\d+'), '');
|
||||
// 移除残留 HTML 标签
|
||||
t = t.replaceAll(RegExp(r'<[^>]+>'), '');
|
||||
// 行首 # 超过 3 个降为 ###
|
||||
t = t.replaceAllMapped(RegExp(r'^#{4,}\s', multiLine: true), (_) => '### ');
|
||||
// 压缩多余空行
|
||||
t = t.replaceAll(RegExp(r'\n{3,}'), '\n\n');
|
||||
return t.trim();
|
||||
}
|
||||
|
||||
/// 处理 AI 回复里的 markdown 链接点击:
|
||||
/// - app://diet → 触发拍照/相册选择,跳到饮食拍照流程
|
||||
@@ -2098,77 +2082,3 @@ extension _AgentActionsExt on ActiveAgent {
|
||||
_agentActions[this] ??
|
||||
[const _AgentAction(label: '开始对话', icon: Icons.chat_outlined)];
|
||||
}
|
||||
|
||||
// ════════════════════════════════════════════════════════════════
|
||||
// 可展开的 AI 建议小组件
|
||||
// ════════════════════════════════════════════════════════════════
|
||||
|
||||
class _ExpandableAdvice extends StatefulWidget {
|
||||
final String advice;
|
||||
const _ExpandableAdvice({required this.advice});
|
||||
|
||||
@override
|
||||
State<_ExpandableAdvice> createState() => _ExpandableAdviceState();
|
||||
}
|
||||
|
||||
class _ExpandableAdviceState extends State<_ExpandableAdvice> {
|
||||
bool _expanded = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () => setState(() => _expanded = !_expanded),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.backgroundSecondary,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFE8E4FF), width: 0.8),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(
|
||||
Icons.lightbulb_outline,
|
||||
size: 19,
|
||||
color: AppTheme.primary,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
const Text(
|
||||
'AI 建议',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppTheme.primary,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Icon(
|
||||
_expanded
|
||||
? Icons.keyboard_arrow_up
|
||||
: Icons.keyboard_arrow_down,
|
||||
size: 21,
|
||||
color: AppColors.textHint,
|
||||
),
|
||||
],
|
||||
),
|
||||
if (_expanded) ...[
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
widget.advice,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
color: Color(0xFF555555),
|
||||
height: 1.6,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user