generateDailyRecommendation static method
生成每日推荐
Implementation
static Future<String> generateDailyRecommendation() async {
final weather = await WeatherService.getTomorrowWeather();
final allItems = await WardrobeService.getAllClothingItems();
if (weather == null || allItems.isEmpty) {
return '早上好!今天是美好的一天!';
}
StringBuffer recommendation = StringBuffer();
recommendation.write('早上好!');
// 天气信息
if (weather.temperature < 15) {
recommendation.write('明天降温至${weather.temperature.toInt()}°C');
if (weather.needsUmbrella) {
recommendation.write(',有${weather.condition}');
}
recommendation.write('。');
} else {
recommendation.write('明天${weather.condition},温度${weather.temperature.toInt()}°C。');
}
// 从衣橱中推荐
final outerwear = allItems.where((item) => item.category == ClothingCategory.outerwear).toList();
final shoes = allItems.where((item) => item.category == ClothingCategory.shoes).toList();
if (weather.temperature < 15 && outerwear.isNotEmpty) {
final jacket = outerwear.first;
recommendation.write('建议您穿上「虚拟衣橱」里的${jacket.name}');
if (shoes.isNotEmpty) {
final shoe = shoes.first;
recommendation.write(',搭配${shoe.name}');
}
recommendation.write(',会非常优雅哦。');
} else if (outerwear.isNotEmpty || shoes.isNotEmpty) {
recommendation.write('从您的衣橱中为您推荐今日搭配!');
}
return recommendation.toString();
}