|
|
|
@ -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)], |
|
|
|
); |
|
|
|
} |
|
|
|
|