Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
F
flutter-chat
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
songchuancai
flutter-chat
Commits
a60101b5
提交
a60101b5
authored
11月 08, 2024
作者:
songchuancai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加markdown的效果
上级
f21dc626
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
94 行增加
和
11 行删除
+94
-11
home_page.dart
lib/home_page.dart
+46
-9
chat_message.dart
lib/models/chat_message.dart
+5
-2
pubspec.lock
pubspec.lock
+40
-0
pubspec.yaml
pubspec.yaml
+3
-0
没有找到文件。
lib/home_page.dart
浏览文件 @
a60101b5
...
@@ -12,6 +12,7 @@ import 'services/chat_service.dart';
...
@@ -12,6 +12,7 @@ import 'services/chat_service.dart';
import
'models/chat_message.dart'
;
import
'models/chat_message.dart'
;
import
'models/user.dart'
;
import
'models/user.dart'
;
import
'package:shared_preferences/shared_preferences.dart'
;
import
'package:shared_preferences/shared_preferences.dart'
;
import
'package:flutter_markdown/flutter_markdown.dart'
;
class
HomePage
extends
StatefulWidget
{
class
HomePage
extends
StatefulWidget
{
const
HomePage
({
super
.
key
});
const
HomePage
({
super
.
key
});
...
@@ -635,15 +636,51 @@ class _HomePageState extends State<HomePage> {
...
@@ -635,15 +636,51 @@ class _HomePageState extends State<HomePage> {
!
message
.
isUserMessage
?
Radius
.
zero
:
null
,
!
message
.
isUserMessage
?
Radius
.
zero
:
null
,
),
),
),
),
child:
Text
(
child:
message
.
isUserMessage
message
.
text
,
?
Text
(
style:
TextStyle
(
message
.
text
,
color:
message
.
isUserMessage
style:
const
TextStyle
(
?
Colors
.
white
color:
Colors
.
white
,
:
Colors
.
black
,
fontSize:
16
,
fontSize:
16
,
),
),
)
),
:
MarkdownBody
(
data:
message
.
text
,
selectable:
true
,
styleSheet:
MarkdownStyleSheet
(
p:
const
TextStyle
(
color:
Colors
.
black
,
fontSize:
16
,
),
code:
const
TextStyle
(
color:
Colors
.
white
,
fontFamily:
'monospace'
,
fontSize:
14
,
height:
1.5
,
backgroundColor:
Colors
.
transparent
,
),
codeblockPadding:
const
EdgeInsets
.
all
(
16
),
codeblockDecoration:
BoxDecoration
(
color:
const
Color
(
0xFF1E1E1E
),
borderRadius:
BorderRadius
.
circular
(
8
),
),
blockquote:
const
TextStyle
(
color:
Colors
.
black87
,
fontSize:
16
,
height:
1.5
,
),
blockquoteDecoration:
BoxDecoration
(
border:
Border
(
left:
BorderSide
(
color:
Colors
.
grey
[
300
]!,
width:
4
,
),
),
),
listBullet:
const
TextStyle
(
color:
Colors
.
black87
),
),
),
),
),
),
),
if
(
_isLoading
&&
if
(
_isLoading
&&
...
...
lib/models/chat_message.dart
浏览文件 @
a60101b5
...
@@ -2,22 +2,26 @@ class ChatMessage {
...
@@ -2,22 +2,26 @@ class ChatMessage {
final
String
text
;
final
String
text
;
final
bool
isUserMessage
;
final
bool
isUserMessage
;
final
DateTime
timestamp
;
final
DateTime
timestamp
;
final
bool
isMarkdown
;
ChatMessage
({
ChatMessage
({
required
this
.
text
,
required
this
.
text
,
required
this
.
isUserMessage
,
required
this
.
isUserMessage
,
DateTime
?
timestamp
,
DateTime
?
timestamp
,
this
.
isMarkdown
=
true
,
})
:
timestamp
=
timestamp
??
DateTime
.
now
();
})
:
timestamp
=
timestamp
??
DateTime
.
now
();
Map
<
String
,
dynamic
>
toJson
()
=>
{
Map
<
String
,
dynamic
>
toJson
()
=>
{
'text'
:
text
,
'text'
:
text
,
'isUserMessage'
:
isUserMessage
,
'isUserMessage'
:
isUserMessage
,
'timestamp'
:
timestamp
.
toIso8601String
(),
'timestamp'
:
timestamp
.
toIso8601String
(),
'isMarkdown'
:
isMarkdown
,
};
};
factory
ChatMessage
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
=>
ChatMessage
(
factory
ChatMessage
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
=>
ChatMessage
(
text:
json
[
'text'
],
text:
json
[
'text'
],
isUserMessage:
json
[
'isUserMessage'
],
isUserMessage:
json
[
'isUserMessage'
],
timestamp:
DateTime
.
parse
(
json
[
'timestamp'
]),
timestamp:
DateTime
.
parse
(
json
[
'timestamp'
]),
isMarkdown:
json
[
'isMarkdown'
],
);
);
}
}
\ No newline at end of file
pubspec.lock
浏览文件 @
a60101b5
...
@@ -9,6 +9,14 @@ packages:
...
@@ -9,6 +9,14 @@ packages:
url: "https://pub.flutter-io.cn"
url: "https://pub.flutter-io.cn"
source: hosted
source: hosted
version: "3.3.4"
version: "3.3.4"
args:
dependency: transitive
description:
name: args
sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.6.0"
async:
async:
dependency: transitive
dependency: transitive
description:
description:
...
@@ -102,6 +110,14 @@ packages:
...
@@ -102,6 +110,14 @@ packages:
description: flutter
description: flutter
source: sdk
source: sdk
version: "0.0.0"
version: "0.0.0"
flutter_highlight:
dependency: "direct main"
description:
name: flutter_highlight
sha256: "7b96333867aa07e122e245c033b8ad622e4e3a42a1a2372cbb098a2541d8782c"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.7.0"
flutter_lints:
flutter_lints:
dependency: "direct dev"
dependency: "direct dev"
description:
description:
...
@@ -110,6 +126,14 @@ packages:
...
@@ -110,6 +126,14 @@ packages:
url: "https://pub.flutter-io.cn"
url: "https://pub.flutter-io.cn"
source: hosted
source: hosted
version: "2.0.3"
version: "2.0.3"
flutter_markdown:
dependency: "direct main"
description:
name: flutter_markdown
sha256: "04c4722cc36ec5af38acc38ece70d22d3c2123c61305d555750a091517bbe504"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.6.23"
flutter_test:
flutter_test:
dependency: "direct dev"
dependency: "direct dev"
description: flutter
description: flutter
...
@@ -128,6 +152,14 @@ packages:
...
@@ -128,6 +152,14 @@ packages:
description: flutter
description: flutter
source: sdk
source: sdk
version: "0.0.0"
version: "0.0.0"
highlight:
dependency: transitive
description:
name: highlight
sha256: "5353a83ffe3e3eca7df0abfb72dcf3fa66cc56b953728e7113ad4ad88497cf21"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.7.0"
http:
http:
dependency: "direct main"
dependency: "direct main"
description:
description:
...
@@ -192,6 +224,14 @@ packages:
...
@@ -192,6 +224,14 @@ packages:
url: "https://pub.flutter-io.cn"
url: "https://pub.flutter-io.cn"
source: hosted
source: hosted
version: "2.1.1"
version: "2.1.1"
markdown:
dependency: "direct main"
description:
name: markdown
sha256: ef2a1298144e3f985cc736b22e0ccdaf188b5b3970648f2d9dc13efd1d9df051
url: "https://pub.flutter-io.cn"
source: hosted
version: "7.2.2"
matcher:
matcher:
dependency: transitive
dependency: transitive
description:
description:
...
...
pubspec.yaml
浏览文件 @
a60101b5
...
@@ -40,6 +40,9 @@ dependencies:
...
@@ -40,6 +40,9 @@ dependencies:
animate_do
:
^3.0.2
animate_do
:
^3.0.2
shared_preferences
:
^2.0.15
shared_preferences
:
^2.0.15
uuid
:
^4.3.3
uuid
:
^4.3.3
flutter_markdown
:
^0.6.18
flutter_highlight
:
^0.7.0
markdown
:
^7.1.1
dev_dependencies
:
dev_dependencies
:
flutter_test
:
flutter_test
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论