feat: Enhance TV support and Daily Weather Forecast (w/ Air Quality)
- **Frontend (Flutter)**
- Optimize for Google TV: Force Landscape mode, disable touchscreen requirement, and set TV Dashboard as default home.
- Weather Widget:
- Add Daily Max/Min temperature ('최고/최저').
- Add Air Quality Index (AQI) with visual indicator ('미세먼지').
- Increase font sizes and adjust layout to match Digital Clock style.
- Implement 1-hour auto-refresh timer.
- Model: Update WeatherInfo to support tempMin, tempMax, and aqi.
- **Backend (Node.js)**
- Weather API (/api/weather):
- Implement daily forecast aggregation logic (Seoul Time KST) to calculate accurate daily High/Low.
- Integrate OpenWeatherMap Air Pollution API to fetch AQI.
This commit is contained in:
@@ -5,9 +5,92 @@ import '../config/api_config.dart';
|
||||
import '../models/weather_info.dart';
|
||||
import '../services/weather_service.dart';
|
||||
|
||||
class WeatherWidget extends StatelessWidget {
|
||||
class WeatherWidget extends StatefulWidget {
|
||||
const WeatherWidget({super.key});
|
||||
|
||||
@override
|
||||
State<WeatherWidget> createState() => _WeatherWidgetState();
|
||||
}
|
||||
|
||||
class _WeatherWidgetState extends State<WeatherWidget> {
|
||||
Timer? _refreshTimer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Refresh weather every 1 hour
|
||||
_refreshTimer = Timer.periodic(const Duration(hours: 1), (timer) {
|
||||
if (mounted) {
|
||||
setState(() {}); // Rebuild to trigger FutureBuilder
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_refreshTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget _buildAqiIcon(int aqi) {
|
||||
Color color;
|
||||
IconData icon;
|
||||
String label;
|
||||
|
||||
switch (aqi) {
|
||||
case 1: // Good
|
||||
color = Colors.blue;
|
||||
icon = Icons.sentiment_very_satisfied;
|
||||
label = "좋음";
|
||||
break;
|
||||
case 2: // Fair
|
||||
color = Colors.green;
|
||||
icon = Icons.sentiment_satisfied;
|
||||
label = "보통";
|
||||
break;
|
||||
case 3: // Moderate
|
||||
color = Colors.yellow[700]!;
|
||||
icon = Icons.sentiment_neutral;
|
||||
label = "주의";
|
||||
break;
|
||||
case 4: // Poor
|
||||
color = Colors.orange;
|
||||
icon = Icons.sentiment_dissatisfied;
|
||||
label = "나쁨";
|
||||
break;
|
||||
case 5: // Very Poor
|
||||
color = Colors.red;
|
||||
icon = Icons.sentiment_very_dissatisfied;
|
||||
label = "매우 나쁨";
|
||||
break;
|
||||
default:
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.2),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: color, width: 2),
|
||||
),
|
||||
child: Icon(icon, color: color, size: 20),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: color,
|
||||
fontSize: 10,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<WeatherInfo>(
|
||||
@@ -27,6 +110,7 @@ class WeatherWidget extends StatelessWidget {
|
||||
}
|
||||
|
||||
if (snapshot.hasError) {
|
||||
debugPrint('Weather Error: ${snapshot.error}');
|
||||
return const Text(
|
||||
'Weather Unavailable',
|
||||
style: TextStyle(color: Colors.white54),
|
||||
@@ -42,42 +126,87 @@ class WeatherWidget extends StatelessWidget {
|
||||
final iconUrl = (ApiConfig.useMockData || kIsWeb)
|
||||
? null
|
||||
: (weather.icon.isNotEmpty
|
||||
? "http://openweathermap.org/img/wn/${weather.icon}@2x.png"
|
||||
? "https://openweathermap.org/img/wn/${weather.icon}@2x.png"
|
||||
: null);
|
||||
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
// Weather Icon
|
||||
if (iconUrl != null)
|
||||
Image.network(
|
||||
iconUrl,
|
||||
width: 50,
|
||||
height: 50,
|
||||
width: 72,
|
||||
height: 72,
|
||||
errorBuilder: (_, __, ___) =>
|
||||
const Icon(Icons.wb_sunny, color: Colors.amber),
|
||||
)
|
||||
else
|
||||
const Icon(Icons.wb_sunny, color: Colors.amber, size: 40),
|
||||
const SizedBox(width: 12),
|
||||
const Icon(Icons.wb_sunny, color: Colors.amber, size: 60),
|
||||
const SizedBox(width: 16),
|
||||
|
||||
// Temperature & City info
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'${weather.temperature.round()}°C',
|
||||
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${weather.city} · ${weather.description}',
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.bodyMedium?.copyWith(color: Colors.white70),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.baseline,
|
||||
textBaseline: TextBaseline.alphabetic,
|
||||
children: [
|
||||
Text(
|
||||
'${weather.temperature.round()}°',
|
||||
style: Theme.of(context).textTheme.displaySmall?.copyWith(
|
||||
fontSize: 42, // Slightly larger to stand out
|
||||
color: Colors.yellowAccent,
|
||||
fontWeight: FontWeight.bold,
|
||||
height: 1.0,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${weather.city} · ${weather.description}',
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
color: Colors.white70,
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 20
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'최고:${weather.tempMax.round()}° 최저:${weather.tempMin.round()}°',
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
color: Colors.white,
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// AQI Indicator (Right side)
|
||||
if (weather.aqi > 0) ...[
|
||||
const SizedBox(width: 24),
|
||||
Container(
|
||||
height: 50,
|
||||
width: 2,
|
||||
color: Colors.white24,
|
||||
),
|
||||
const SizedBox(width: 24),
|
||||
// Scaled up AQI
|
||||
Transform.scale(
|
||||
scale: 1.2,
|
||||
child: _buildAqiIcon(weather.aqi),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user