Browse Source

refactor(agent): 优化天气卡片背景渐变逻辑并移除未使用的BLE订阅

将天气卡片的背景渐变逻辑提取为独立方法,根据天气类型返回不同的渐变颜色
移除agent_controller中未使用的BLE事件订阅代码
weicu
lxm 1 year ago
parent
commit
6f1c1fa4d4
  1. 2
      lib/modules/agent/controllers/agent_controller.dart
  2. 101
      lib/modules/agent/views/weather_card.dart

2
lib/modules/agent/controllers/agent_controller.dart

@ -160,7 +160,7 @@ class AgentController extends GetxController {
_setupScrollListener(); //设置滚动监听器
_loadChatHistory(); //加载聊天历史记录
_subscribeToEvents(); //订阅代理服务事件
_subscribeToBleEvents(); //订阅BLE事件
// _subscribeToBleEvents(); //订阅BLE事件
_initMusicStatus(); //初始化音乐状态
_setupMediaSessionCallbacks(); //设置媒体会话回调
_setupTextInputListener(); //设置文本输入监听器

101
lib/modules/agent/views/weather_card.dart

@ -25,17 +25,7 @@ Widget buildWeatherContent(BuildContext context, String city,
Container(
padding: EdgeInsets.all(16.w),
decoration: BoxDecoration(
gradient: isDarkMode
? const LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color(0xFF1E40AF), Color(0xFF1E3A8A)],
)
: const LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color(0xFF60A5FA), Color(0xFF3B82F6)],
),
gradient: _getWeatherGradient(now['dayweather'] ?? '', isDarkMode),
borderRadius: BorderRadius.circular(12.r),
boxShadow: [
BoxShadow(
@ -63,7 +53,7 @@ Widget buildWeatherContent(BuildContext context, String city,
color: Colors.white,
),
),
SizedBox(height: 4),
SizedBox(height: 4.w),
Text(
_getWeatherDescriptionTranslation(now["dayweather"]),
style: TextStyle(
@ -483,3 +473,90 @@ IconData getWeatherIcon(String description) {
// 默认或未知天气
return Icons.help_outline;
}
/// 根据天气类型获取背景渐变颜色
LinearGradient _getWeatherGradient(String weather, bool isDarkMode) {
final weatherType = weather.trim();
// 晴天 - 温暖的橙黄色
if (['晴', '少云', '晴间多云'].any((sunny) => weatherType.contains(sunny))) {
return LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: isDarkMode
? [Color(0xFFFF8A00), Color(0xFFE65100)] // 深色模式:深橙色
: [Color(0xFFFFB74D), Color(0xFFFF9800)], // 浅色模式:亮橙色
);
}
// 多云/阴天 - 灰蓝色
if (['多云', '阴'].any((cloudy) => weatherType.contains(cloudy))) {
return LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: isDarkMode
? [Color(0xFF455A64), Color(0xFF37474F)] // 深色模式:深灰蓝
: [Color(0xFF78909C), Color(0xFF607D8B)], // 浅色模式:灰蓝色
);
}
// 雨天 - 深蓝色
if (weatherType.contains('雨') ||
['阵雨', '雷阵雨', '小雨', '中雨', '大雨', '暴雨']
.any((rain) => weatherType.contains(rain))) {
return LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: isDarkMode
? [Color(0xFF1565C0), Color(0xFF0D47A1)] // 深色模式:深蓝色
: [Color(0xFF42A5F5), Color(0xFF1976D2)], // 浅色模式:亮蓝色
);
}
// 雪天 - 冷色调蓝白色
if (weatherType.contains('雪') ||
['阵雪', '小雪', '中雪', '大雪', '暴雪']
.any((snow) => weatherType.contains(snow))) {
return LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: isDarkMode
? [Color(0xFF0277BD), Color(0xFF01579B)] // 深色模式:深冷蓝
: [Color(0xFF81D4FA), Color(0xFF29B6F6)], // 浅色模式:浅蓝色
);
}
// 雾霾天 - 暗黄灰色
if (weatherType.contains('雾') ||
weatherType.contains('霾') ||
['雾', '浓雾', '霾', '中度霾', '重度霾'].any((fog) => weatherType.contains(fog))) {
return LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: isDarkMode
? [Color(0xFF5D4037), Color(0xFF3E2723)] // 深色模式:深棕色
: [Color(0xFF8D6E63), Color(0xFF6D4C41)], // 浅色模式:棕灰色
);
}
// 大风天 - 青绿色
if (weatherType.contains('风') ||
['大风', '强风', '疾风', '烈风'].any((wind) => weatherType.contains(wind))) {
return LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: isDarkMode
? [Color(0xFF00695C), Color(0xFF004D40)] // 深色模式:深青色
: [Color(0xFF26A69A), Color(0xFF00796B)], // 浅色模式:青绿色
);
}
// 默认 - 原来的蓝色
return LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: isDarkMode
? [Color(0xFF1E40AF), Color(0xFF1E3A8A)]
: [Color(0xFF60A5FA), Color(0xFF3B82F6)],
);
}

Loading…
Cancel
Save