提交 a60101b5 authored 作者: songchuancai's avatar songchuancai

增加markdown的效果

上级 f21dc626
......@@ -12,6 +12,7 @@ import 'services/chat_service.dart';
import 'models/chat_message.dart';
import 'models/user.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
class HomePage extends StatefulWidget {
const HomePage({super.key});
......@@ -635,14 +636,50 @@ class _HomePageState extends State<HomePage> {
!message.isUserMessage ? Radius.zero : null,
),
),
child: Text(
child: message.isUserMessage
? Text(
message.text,
style: TextStyle(
color: message.isUserMessage
? Colors.white
: Colors.black,
style: const TextStyle(
color: Colors.white,
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),
),
),
),
),
......
......@@ -2,22 +2,26 @@ class ChatMessage {
final String text;
final bool isUserMessage;
final DateTime timestamp;
final bool isMarkdown;
ChatMessage({
required this.text,
required this.isUserMessage,
DateTime? timestamp,
this.isMarkdown = true,
}) : timestamp = timestamp ?? DateTime.now();
Map<String, dynamic> toJson() => {
'text': text,
'isUserMessage': isUserMessage,
'timestamp': timestamp.toIso8601String(),
'isMarkdown': isMarkdown,
};
factory ChatMessage.fromJson(Map<String, dynamic> json) => ChatMessage(
text: json['text'],
isUserMessage: json['isUserMessage'],
timestamp: DateTime.parse(json['timestamp']),
isMarkdown: json['isMarkdown'],
);
}
......@@ -9,6 +9,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
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:
dependency: transitive
description:
......@@ -102,6 +110,14 @@ packages:
description: flutter
source: sdk
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:
dependency: "direct dev"
description:
......@@ -110,6 +126,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
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:
dependency: "direct dev"
description: flutter
......@@ -128,6 +152,14 @@ packages:
description: flutter
source: sdk
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:
dependency: "direct main"
description:
......@@ -192,6 +224,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
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:
dependency: transitive
description:
......
......@@ -40,6 +40,9 @@ dependencies:
animate_do: ^3.0.2
shared_preferences: ^2.0.15
uuid: ^4.3.3
flutter_markdown: ^0.6.18
flutter_highlight: ^0.7.0
markdown: ^7.1.1
dev_dependencies:
flutter_test:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论