|
|
@@ -6,6 +6,7 @@ import 'package:electronic_assistant/data/bean/reference_chat_item.dart';
|
|
|
import 'package:electronic_assistant/module/browser/view.dart';
|
|
|
import 'package:electronic_assistant/module/chat/controller.dart';
|
|
|
import 'package:electronic_assistant/resource/colors.gen.dart';
|
|
|
+import 'package:electronic_assistant/resource/string.gen.dart';
|
|
|
import 'package:electronic_assistant/utils/expand.dart';
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
@@ -253,7 +254,8 @@ class ChatPage extends BasePage<ChatController> {
|
|
|
alignment: Alignment.centerLeft,
|
|
|
child: IntrinsicWidth(
|
|
|
child: progressingChatItem == null
|
|
|
- ? _buildAssistantChatItemContent(null, chatItem.content)
|
|
|
+ ? _buildAssistantChatItemContent(
|
|
|
+ null, chatItem.content, chatItem.id)
|
|
|
: Obx(() {
|
|
|
bool? isStreamStarted = progressingChatItem == null
|
|
|
? null
|
|
|
@@ -264,59 +266,154 @@ class ChatPage extends BasePage<ChatController> {
|
|
|
isStreamStarted,
|
|
|
progressingChatItem!.isFailed.value
|
|
|
? progressingChatItem.error.value
|
|
|
- : progressingChatItem.streamContent.value);
|
|
|
+ : progressingChatItem.streamContent.value,
|
|
|
+ chatItem.id);
|
|
|
}),
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- Container _buildAssistantChatItemContent(
|
|
|
- bool? isStreamStarted, String content) {
|
|
|
- return Container(
|
|
|
- padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 8.h),
|
|
|
- margin: EdgeInsets.symmetric(vertical: 10.h),
|
|
|
- alignment: Alignment.centerLeft,
|
|
|
- constraints: BoxConstraints(
|
|
|
- maxWidth: 0.78.sw,
|
|
|
- ),
|
|
|
- decoration: BoxDecoration(
|
|
|
- border: isStreamStarted == null || isStreamStarted == true
|
|
|
- ? null
|
|
|
- : Border.all(color: ColorName.colorPrimary, width: 1.w),
|
|
|
- color: ColorName.white,
|
|
|
- borderRadius: BorderRadius.only(
|
|
|
- topRight: Radius.circular(20.w),
|
|
|
- bottomRight: Radius.circular(20.w),
|
|
|
- bottomLeft: Radius.circular(20.w))),
|
|
|
- child: isStreamStarted != null && isStreamStarted == false
|
|
|
- ? Lottie.asset("assets/anim/anim_chat_response_loading.zip",
|
|
|
- width: 46.w, height: 20.w)
|
|
|
- : SelectionArea(
|
|
|
- child: HtmlWidget(
|
|
|
- onTapUrl: (url) {
|
|
|
- BrowserPage.start(url);
|
|
|
- return true;
|
|
|
- },
|
|
|
- md.markdownToHtml(content, inlineSyntaxes: [
|
|
|
- md.InlineHtmlSyntax(),
|
|
|
- md.StrikethroughSyntax(),
|
|
|
- md.EmojiSyntax(),
|
|
|
- md.ColorSwatchSyntax(),
|
|
|
- md.AutolinkExtensionSyntax(),
|
|
|
- md.ImageSyntax()
|
|
|
- ], blockSyntaxes: [
|
|
|
- const md.FencedCodeBlockSyntax(),
|
|
|
- const md.HeaderWithIdSyntax(),
|
|
|
- const md.SetextHeaderWithIdSyntax(),
|
|
|
- const md.UnorderedListWithCheckboxSyntax(),
|
|
|
- const md.OrderedListWithCheckboxSyntax(),
|
|
|
- const md.FootnoteDefSyntax(),
|
|
|
- const md.AlertBlockSyntax(),
|
|
|
- ]),
|
|
|
- textStyle: TextStyle(
|
|
|
- fontSize: 14.w, color: ColorName.primaryTextColor),
|
|
|
+ Widget _buildAssistantChatItemContent(
|
|
|
+ bool? isStreamStarted, String content, String id) {
|
|
|
+ return Column(
|
|
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
+ children: [
|
|
|
+ SizedBox(height: 10.h),
|
|
|
+ isStreamStarted != null && isStreamStarted == false
|
|
|
+ ? Container(
|
|
|
+ padding: const EdgeInsets.all(1),
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ color: ColorName.colorPrimary,
|
|
|
+ gradient: LinearGradient(
|
|
|
+ colors: ['#B57AFF'.toColor(), '#4466FF'.toColor()],
|
|
|
+ stops: const [0, 1.0],
|
|
|
+ begin: Alignment.topLeft,
|
|
|
+ end: Alignment.bottomRight,
|
|
|
+ ),
|
|
|
+ borderRadius: BorderRadius.only(
|
|
|
+ topRight: Radius.circular(20.w),
|
|
|
+ bottomRight: Radius.circular(20.w),
|
|
|
+ bottomLeft: Radius.circular(20.w))),
|
|
|
+ child: Container(
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ color: ColorName.white,
|
|
|
+ borderRadius: BorderRadius.only(
|
|
|
+ topRight: Radius.circular(20.w),
|
|
|
+ bottomRight: Radius.circular(20.w),
|
|
|
+ bottomLeft: Radius.circular(20.w))),
|
|
|
+ padding:
|
|
|
+ EdgeInsets.symmetric(horizontal: 12.w, vertical: 8.h),
|
|
|
+ child: Lottie.asset(
|
|
|
+ "assets/anim/anim_chat_response_loading.zip",
|
|
|
+ width: 46.w,
|
|
|
+ height: 20.w)),
|
|
|
+ )
|
|
|
+ : Container(
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ color: ColorName.white,
|
|
|
+ border: Border.all(color: '#ECECEC'.color, width: 1.w),
|
|
|
+ borderRadius: BorderRadius.only(
|
|
|
+ topRight: Radius.circular(20.w),
|
|
|
+ bottomRight: Radius.circular(20.w),
|
|
|
+ bottomLeft: Radius.circular(20.w))),
|
|
|
+ padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 8.h),
|
|
|
+ alignment: Alignment.centerLeft,
|
|
|
+ constraints: BoxConstraints(
|
|
|
+ maxWidth: 0.78.sw,
|
|
|
),
|
|
|
- ));
|
|
|
+ child: SelectionArea(
|
|
|
+ child: HtmlWidget(
|
|
|
+ onTapUrl: (url) {
|
|
|
+ BrowserPage.start(url);
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+ md.markdownToHtml(content, inlineSyntaxes: [
|
|
|
+ md.InlineHtmlSyntax(),
|
|
|
+ md.StrikethroughSyntax(),
|
|
|
+ md.EmojiSyntax(),
|
|
|
+ md.ColorSwatchSyntax(),
|
|
|
+ md.AutolinkExtensionSyntax(),
|
|
|
+ md.ImageSyntax()
|
|
|
+ ], blockSyntaxes: [
|
|
|
+ const md.FencedCodeBlockSyntax(),
|
|
|
+ const md.HeaderWithIdSyntax(),
|
|
|
+ const md.SetextHeaderWithIdSyntax(),
|
|
|
+ const md.UnorderedListWithCheckboxSyntax(),
|
|
|
+ const md.OrderedListWithCheckboxSyntax(),
|
|
|
+ const md.FootnoteDefSyntax(),
|
|
|
+ const md.AlertBlockSyntax(),
|
|
|
+ ]),
|
|
|
+ textStyle: TextStyle(
|
|
|
+ fontSize: 14.w, color: ColorName.primaryTextColor),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ // Container(
|
|
|
+ // padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 8.h),
|
|
|
+ // alignment: Alignment.centerLeft,
|
|
|
+ // constraints: BoxConstraints(
|
|
|
+ // maxWidth: 0.78.sw,
|
|
|
+ // ),
|
|
|
+ // decoration: BoxDecoration(
|
|
|
+ // border: isStreamStarted == null || isStreamStarted == true
|
|
|
+ // ? null
|
|
|
+ // : Border.all(color: ColorName.colorPrimary, width: 1.w),
|
|
|
+ // color: ColorName.white,
|
|
|
+ // borderRadius: BorderRadius.only(
|
|
|
+ // topRight: Radius.circular(20.w),
|
|
|
+ // bottomRight: Radius.circular(20.w),
|
|
|
+ // bottomLeft: Radius.circular(20.w))),
|
|
|
+ // child: isStreamStarted != null && isStreamStarted == false
|
|
|
+ // ? Lottie.asset("assets/anim/anim_chat_response_loading.zip",
|
|
|
+ // width: 46.w, height: 20.w)
|
|
|
+ // : SelectionArea(
|
|
|
+ // child: HtmlWidget(
|
|
|
+ // onTapUrl: (url) {
|
|
|
+ // BrowserPage.start(url);
|
|
|
+ // return true;
|
|
|
+ // },
|
|
|
+ // md.markdownToHtml(content, inlineSyntaxes: [
|
|
|
+ // md.InlineHtmlSyntax(),
|
|
|
+ // md.StrikethroughSyntax(),
|
|
|
+ // md.EmojiSyntax(),
|
|
|
+ // md.ColorSwatchSyntax(),
|
|
|
+ // md.AutolinkExtensionSyntax(),
|
|
|
+ // md.ImageSyntax()
|
|
|
+ // ], blockSyntaxes: [
|
|
|
+ // const md.FencedCodeBlockSyntax(),
|
|
|
+ // const md.HeaderWithIdSyntax(),
|
|
|
+ // const md.SetextHeaderWithIdSyntax(),
|
|
|
+ // const md.UnorderedListWithCheckboxSyntax(),
|
|
|
+ // const md.OrderedListWithCheckboxSyntax(),
|
|
|
+ // const md.FootnoteDefSyntax(),
|
|
|
+ // const md.AlertBlockSyntax(),
|
|
|
+ // ]),
|
|
|
+ // textStyle: TextStyle(
|
|
|
+ // fontSize: 14.w, color: ColorName.primaryTextColor),
|
|
|
+ // ),
|
|
|
+ // )),
|
|
|
+ Obx(() {
|
|
|
+ return Visibility(
|
|
|
+ visible: id == controller.chatAiTagId.value,
|
|
|
+ child: Container(
|
|
|
+ margin: EdgeInsets.only(top: 6.h),
|
|
|
+ padding: EdgeInsets.symmetric(horizontal: 6.w, vertical: 3.w),
|
|
|
+ decoration: BoxDecoration(
|
|
|
+ borderRadius: BorderRadius.all(Radius.circular(12.w)),
|
|
|
+ color: "#EFEEF1".color),
|
|
|
+ child: Text(
|
|
|
+ StringName.chatItemAiTag.tr,
|
|
|
+ style: TextStyle(
|
|
|
+ height: 1,
|
|
|
+ fontSize: 10.sp,
|
|
|
+ color: ColorName.tertiaryTextColor),
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ }),
|
|
|
+ SizedBox(height: 10.h)
|
|
|
+ ],
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
Widget _buildUserChatItem(BuildContext context, ChatItem chatItem) {
|