Browse Source

修改音乐播放

newdev_shunjiawei
tanlongsheng 2 years ago
parent
commit
cd5fcfc66b
  1. 10
      lib/modules/chat/controllers/chat_controller.dart
  2. 12
      lib/modules/chat/models/message_model.dart
  3. 14
      lib/modules/chat/views/chat_view.dart
  4. 76
      lib/modules/chat/views/weather_day_card.dart

10
lib/modules/chat/controllers/chat_controller.dart

@ -397,7 +397,7 @@ class ChatController extends GetxController {
if (_shouldCancelAiResponse) return;
Logger.info('chat ${chunk}');
if (chunk is Map) {
_updateIntermediateMessage(data: chunk);
_updateIntermediateMessage(meta: chunk);
if (chunk['card_spotify'] != null) {
play(chunk['card_spotify']);
}
@ -465,14 +465,14 @@ class ChatController extends GetxController {
}
// 更新中间状态的消息
void _updateIntermediateMessage({Map? data, String? content}) {
void _updateIntermediateMessage({Map? meta, String? content}) {
final index =
messages.indexWhere((m) => m.isIntermediate && m.role == 'assistant');
if (index != -1) {
if (data != null) {
Map messagesData = messages[index].data ?? {};
if (meta != null) {
Map messagesData = messages[index].meta ?? {};
messages[index] = messages[index].copyWith(
data: {...messagesData, ...data},
meta: {...messagesData, ...meta},
);
}
messages[index] = messages[index].copyWith(

12
lib/modules/chat/models/message_model.dart

@ -1,7 +1,7 @@
class Message {
final String role; // 'user' or 'assistant'
final String content;
final Map? data;
final Map? meta;
final DateTime timestamp;
final bool isIntermediate; // 中间状态标记,替代isLoading
@ -9,7 +9,7 @@ class Message {
required this.role,
required this.content,
required this.timestamp,
this.data,
this.meta,
this.isIntermediate = false, // 默认不是中间状态
});
@ -18,7 +18,7 @@ class Message {
return Message(
role: json['role'] as String,
content: json['content'] as String,
data: json['data'],
meta: json['meta'],
timestamp: DateTime.parse(json['timestamp'] as String),
isIntermediate: json['isIntermediate'] as bool? ?? false,
);
@ -29,7 +29,7 @@ class Message {
return {
'role': role,
'content': content,
'data': data,
'meta': meta,
'timestamp': timestamp.toIso8601String(),
'isIntermediate': isIntermediate,
};
@ -49,14 +49,14 @@ class Message {
Message copyWith({
String? role,
String? content,
Map? data,
Map? meta,
DateTime? timestamp,
bool? isIntermediate,
}) {
return Message(
role: role ?? this.role,
content: content ?? this.content,
data: data ?? this.data,
meta: meta ?? this.meta,
timestamp: timestamp ?? this.timestamp,
isIntermediate: isIntermediate ?? this.isIntermediate,
);

14
lib/modules/chat/views/chat_view.dart

@ -355,16 +355,16 @@ class ChatView extends GetView<ChatController> {
),
);
}
if (message.data != null) {
if (message.data?['card_weather'] != null) {
box = WeatherDayCard(message.data?['card_weather'], isDarkMode);
if (message.meta != null) {
if (message.meta?['card_weather'] != null) {
box = WeatherDayCard(message.meta?['card_weather'], isDarkMode);
}
if (message.data?['card_spotify'] != null) {
box = ChatMusicCard(message.data?['card_spotify'], isDarkMode);
if (message.meta?['card_spotify'] != null) {
box = ChatMusicCard(message.meta?['card_spotify'], isDarkMode);
}
if (message.data?['card_navigation'] != null) {
if (message.meta?['card_navigation'] != null) {
box = ChatNavigationCard(
message.data?['card_navigation'], message.content, isDarkMode);
message.meta?['card_navigation'], message.content, isDarkMode);
}
}
return box;

76
lib/modules/chat/views/weather_day_card.dart

@ -17,7 +17,7 @@ class WeatherDayCard extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
data?['date'],
data?['city'],
style: TextStyle(
color: isDarkMode ? Colors.white : Colors.black,
fontSize: 10.sp,
@ -47,43 +47,43 @@ class WeatherDayCard extends StatelessWidget {
fontSize: 14.sp,
),
),
// Row(
// children: [
// Text(
// '最\n高',
// style: TextStyle(
// color: isDarkMode ? Colors.white : Colors.black,
// fontSize: 10.sp,
// height: 1,
// ),
// ),
// 5.horizontalSpace,
// Text(
// '${data?['maxTemperature']}°',
// style: TextStyle(
// color: isDarkMode ? Colors.white : Colors.black,
// fontSize: 20.sp,
// ),
// ),
// 10.horizontalSpace,
// Text(
// '最\n低',
// style: TextStyle(
// color: isDarkMode ? Colors.white : Colors.black,
// fontSize: 10.sp,
// height: 1,
// ),
// ),
// 5.horizontalSpace,
// Text(
// '${data?['minTemperature']}°',
// style: TextStyle(
// color: isDarkMode ? Colors.white : Colors.black,
// fontSize: 20.sp,
// ),
// ),
// ],
// ),
Row(
children: [
Text(
'湿\n度',
style: TextStyle(
color: isDarkMode ? Colors.white : Colors.black,
fontSize: 10.sp,
height: 1,
),
),
5.horizontalSpace,
Text(
'${data?['humidity']}',
style: TextStyle(
color: isDarkMode ? Colors.white : Colors.black,
fontSize: 20.sp,
),
),
10.horizontalSpace,
Text(
'风\n力',
style: TextStyle(
color: isDarkMode ? Colors.white : Colors.black,
fontSize: 10.sp,
height: 1,
),
),
5.horizontalSpace,
Text(
'${data?['windForce']}',
style: TextStyle(
color: isDarkMode ? Colors.white : Colors.black,
fontSize: 20.sp,
),
),
],
),
],
),
],

Loading…
Cancel
Save