Skip to content

Commit 37f9893

Browse files
committed
fix:修正卸载后重新导入了备份数据,因对话记录保存的资源缓存地址不存在而各种报错的相关问题(提示用户重新创建对话)
1 parent 6b74508 commit 37f9893

File tree

4 files changed

+65
-21
lines changed

4 files changed

+65
-21
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ enum LLModelType {
225225
- [ ] 测试低成本让少量模型可联网搜索
226226
- [ ] 对话消息展示的 Markdown 格式结合 LaTeX
227227
- [ ] AI 助手可编辑某个输入对话的消息,并记录对话分支
228+
- [ ] 静默继续流式输出(助手模块切换到其他页面时输出继续而不是终止)
228229
- [ ] 添加角色卡功能,可少量预设,支持用户自行导入
229230
- [ ] 一键保存整个对话为 Markdown 文件?
230231
- [ ] 多 Agent 的群聊、角色扮演?

lib/common/components/tool_widget.dart

+26-1
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ Widget buildImageView(
404404
// 是否是本地文件地址(暂时没使用到网络地址)
405405
bool? isFileUrl = false,
406406
String imagePlaceholder = "请选择图片",
407+
String imageErrorHint = "图片异常",
407408
}) {
408409
// 如果没有图片数据,直接返回文提示
409410
if (image == null) {
@@ -444,7 +445,31 @@ Widget buildImageView(
444445
// 默认显示文件图片
445446
child: RepaintBoundary(
446447
child: Center(
447-
child: Image(image: imageProvider, fit: BoxFit.scaleDown),
448+
child: Image(
449+
image: imageProvider,
450+
fit: BoxFit.scaleDown,
451+
errorBuilder: (context, url, error) => Container(
452+
decoration: BoxDecoration(
453+
border: Border.all(color: Colors.grey),
454+
borderRadius: BorderRadius.circular(10.sp),
455+
),
456+
child: Padding(
457+
padding: EdgeInsets.all(5.sp),
458+
child: Column(
459+
mainAxisAlignment: MainAxisAlignment.center,
460+
crossAxisAlignment: CrossAxisAlignment.center,
461+
children: [
462+
Icon(Icons.error, color: Colors.red),
463+
Text(
464+
imageErrorHint,
465+
textAlign: TextAlign.center,
466+
style: TextStyle(color: Colors.red),
467+
),
468+
],
469+
),
470+
),
471+
),
472+
),
448473
),
449474
),
450475
),

lib/views/brief_ai_assistant/chat/components/chat_message_item.dart

+30-20
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import 'package:flutter/material.dart';
22
import 'package:flutter_markdown/flutter_markdown.dart';
33
import 'package:flutter_screenutil/flutter_screenutil.dart';
44
import 'package:intl/intl.dart';
5+
import '../../../../common/components/tool_widget.dart';
56
import '../../../../common/constants/constants.dart';
67
import '../../../../models/brief_ai_tools/chat_competion/com_cc_state.dart';
7-
import 'dart:io';
88

99
import '../../../../common/components/voice_chat_bubble.dart';
1010

@@ -55,14 +55,14 @@ class ChatMessageItem extends StatelessWidget {
5555
_buildVoicePlayer(),
5656

5757
// 显示图片
58-
if (message.imageUrl != null) _buildImage(),
58+
if (message.imageUrl != null) _buildImage(context),
5959
],
6060
),
6161
);
6262
}
6363

6464
// 头像消息体旁边,Row布局,显示文本内容没那么宽
65-
Widget buildHorizontalAvatar(bool isUser) {
65+
Widget buildHorizontalAvatar(bool isUser, BuildContext context) {
6666
return Container(
6767
margin: EdgeInsets.all(4.sp),
6868
child: Row(
@@ -97,7 +97,7 @@ class ChatMessageItem extends StatelessWidget {
9797
_buildVoicePlayer(),
9898

9999
// 显示图片
100-
if (message.imageUrl != null) _buildImage(),
100+
if (message.imageUrl != null) _buildImage(context),
101101
],
102102
),
103103
),
@@ -384,26 +384,36 @@ class ChatMessageItem extends StatelessWidget {
384384
}
385385

386386
// 简单的图片预览
387-
Widget _buildImage() {
387+
Widget _buildImage(BuildContext context) {
388388
return Container(
389389
margin: EdgeInsets.only(top: 8.sp),
390390
child: ClipRRect(
391391
borderRadius: BorderRadius.circular(8.sp),
392-
child: message.imageUrl!.startsWith('http')
393-
? Image.network(
394-
message.imageUrl!,
395-
width: 0.25.sw,
396-
fit: BoxFit.cover,
397-
loadingBuilder: (context, child, loadingProgress) {
398-
if (loadingProgress == null) return child;
399-
return Center(child: CircularProgressIndicator());
400-
},
401-
)
402-
: Image.file(
403-
File(message.imageUrl!),
404-
width: 0.25.sw,
405-
fit: BoxFit.cover,
406-
),
392+
// child: message.imageUrl!.startsWith('http')
393+
// ? Image.network(
394+
// message.imageUrl!,
395+
// width: 0.25.sw,
396+
// fit: BoxFit.cover,
397+
// loadingBuilder: (context, child, loadingProgress) {
398+
// if (loadingProgress == null) return child;
399+
// return Center(child: CircularProgressIndicator());
400+
// },
401+
// )
402+
// : Image.file(
403+
// File(message.imageUrl!),
404+
// width: 0.25.sw,
405+
// fit: BoxFit.cover,
406+
// ),
407+
408+
child: SizedBox(
409+
width: 0.3.sw,
410+
child: buildImageView(
411+
message.imageUrl!,
412+
context,
413+
isFileUrl: true,
414+
imageErrorHint: '图片异常,请开启新对话',
415+
),
416+
),
407417
),
408418
);
409419
}

lib/views/brief_ai_assistant/chat/index.dart

+8
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ class _BriefChatScreenState extends State<BriefChatScreen>
460460
} catch (e) {
461461
if (!mounted) return;
462462
commonExceptionDialog(context, "异常提示", "发送消息失败: $e");
463+
setState(() {
464+
_cancelResponse = null;
465+
_isStreaming = false;
466+
});
463467
}
464468
}
465469

@@ -493,6 +497,10 @@ class _BriefChatScreenState extends State<BriefChatScreen>
493497
} catch (e) {
494498
if (!mounted) return;
495499
commonExceptionDialog(context, "异常提示", "重新生成失败: $e");
500+
setState(() {
501+
_cancelResponse = null;
502+
_isStreaming = false;
503+
});
496504
} finally {
497505
if (mounted) {
498506
setState(() {

0 commit comments

Comments
 (0)