Refine schedule/todo UI and integrate Google Photos API

This commit is contained in:
kihong.kim
2026-02-01 00:30:32 +09:00
parent 7ddd29dfed
commit c614c883d4
15 changed files with 2124 additions and 565 deletions

View File

@@ -0,0 +1,18 @@
const mongoose = require("mongoose");
const googleConfigSchema = new mongoose.Schema(
{
key: { type: String, required: true, unique: true }, // e.g., 'photos_auth'
tokens: {
access_token: String,
refresh_token: String,
scope: String,
token_type: String,
expiry_date: Number,
},
albumId: { type: String }, // Optional: to filter by a specific album
},
{ timestamps: true }
);
module.exports = mongoose.model("GoogleConfig", googleConfigSchema);

File diff suppressed because it is too large Load Diff

View File

@@ -15,6 +15,7 @@
"cors": "^2.8.5",
"dotenv": "^16.4.7",
"express": "^4.19.2",
"googleapis": "^171.0.0",
"mongoose": "^8.9.0",
"multer": "^1.4.5-lts.1"
}

View File

@@ -2,13 +2,24 @@ const express = require("express");
const path = require("path");
const fs = require("fs");
const multer = require("multer");
const { google } = require("googleapis");
const axios = require("axios");
const Photo = require("../models/Photo");
const GoogleConfig = require("../models/GoogleConfig");
const router = express.Router();
const uploadsDir = path.join(__dirname, "..", "uploads");
fs.mkdirSync(uploadsDir, { recursive: true });
const oauth2Client = new google.auth.OAuth2(
process.env.GOOGLE_CLIENT_ID,
process.env.GOOGLE_CLIENT_SECRET,
process.env.GOOGLE_REDIRECT_URI
);
const PHOTOS_SCOPE = ["https://www.googleapis.com/auth/photoslibrary.readonly"];
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, uploadsDir);
@@ -22,15 +33,106 @@ const storage = multer.diskStorage({
const upload = multer({ storage });
// OAuth Endpoints
router.get("/auth/url", (req, res) => {
const url = oauth2Client.generateAuthUrl({
access_type: "offline",
scope: PHOTOS_SCOPE,
prompt: "consent",
});
res.json({ url });
});
router.get("/auth/callback", async (req, res) => {
const { code } = req.query;
try {
const { tokens } = await oauth2Client.getToken(code);
await GoogleConfig.findOneAndUpdate(
{ key: "photos_auth" },
{ tokens },
{ upsert: true }
);
res.send("<h1>Authentication successful!</h1><p>You can close this window and return to the application.</p>");
} catch (error) {
console.error("Auth error:", error);
res.status(500).send("Authentication failed");
}
});
router.get("/status", async (req, res) => {
try {
const config = await GoogleConfig.findOne({ key: "photos_auth" });
res.json({ connected: !!config && !!config.tokens });
} catch (error) {
res.status(500).json({ message: "Failed to check status" });
}
});
router.get("/disconnect", async (req, res) => {
try {
await GoogleConfig.deleteOne({ key: "photos_auth" });
res.json({ ok: true });
} catch (error) {
res.status(500).json({ message: "Failed to disconnect" });
}
});
// Fetching Routes
router.get("/", async (req, res) => {
try {
const filter = {};
if (req.query.active === "true") {
filter.active = true;
}
const photos = await Photo.find(filter).sort({ createdAt: -1 });
res.json(photos);
// Get local photos
const localPhotos = await Photo.find(filter).sort({ createdAt: -1 });
// Check if Google Photos is connected
const config = await GoogleConfig.findOne({ key: "photos_auth" });
if (config && config.tokens) {
try {
oauth2Client.setCredentials(config.tokens);
// Refresh token if needed
if (config.tokens.expiry_date <= Date.now()) {
const { tokens } = await oauth2Client.refreshAccessToken();
config.tokens = tokens;
await config.save();
oauth2Client.setCredentials(tokens);
}
const tokensInfo = await oauth2Client.getAccessToken();
const accessToken = tokensInfo.token;
const response = await axios.get(
"https://photoslibrary.googleapis.com/v1/mediaItems?pageSize=100",
{
headers: { Authorization: `Bearer ${accessToken}` },
}
);
const googlePhotos = (response.data.mediaItems || []).map((item) => ({
id: item.id,
url: `${item.baseUrl}=w2048-h1024`,
caption: item.description || "Google Photo",
active: true,
source: "google"
}));
// Combine local and google photos
return res.json([...localPhotos, ...googlePhotos]);
} catch (gError) {
console.error("Error fetching Google Photos:", gError);
// Fallback to local photos only if Google fails
return res.json(localPhotos);
}
}
res.json(localPhotos);
} catch (error) {
console.error("Fetch error:", error);
res.status(500).json({ message: "Failed to fetch photos" });
}
});

File diff suppressed because it is too large Load Diff

View File

@@ -90,26 +90,37 @@ class _TvDashboardScreenState extends State<TvDashboardScreen> {
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Left Column: Calendar, Schedule, Announcement
// Left Column: Calendar, Bible Verse (Swapped)
Expanded(
flex: 3,
child: Column(
children: [
const Expanded(
flex: 4, child: CalendarWidget()),
flex: 3, child: CalendarWidget()), // Increased flex from 2 to 3
const SizedBox(height: 16),
const Expanded(
flex: 4, child: ScheduleListWidget()),
const SizedBox(height: 16),
const Expanded(
flex: 2, child: AnnouncementWidget()),
flex: 3, child: BibleVerseWidget()), // Reduced flex from 4 to 3
],
),
),
const SizedBox(width: 24),
// Center Column: Photo Slideshow
// Center Column: Todos, Weekly Schedule (Swapped)
Expanded(
flex: 4,
flex: 3, // Reduced from 4 to 3
child: Column(
children: [
const Expanded(
flex: 6, child: TodoListWidget()),
const SizedBox(height: 16),
const Expanded(
flex: 6, child: ScheduleListWidget()),
],
),
),
const SizedBox(width: 24),
// Right Column: Photo Slideshow
Expanded(
flex: 4, // Increased from 3 to 4
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
@@ -125,20 +136,6 @@ class _TvDashboardScreenState extends State<TvDashboardScreen> {
child: const PhotoSlideshowWidget(),
),
),
const SizedBox(width: 24),
// Right Column: Todos, Bible Verse
Expanded(
flex: 3,
child: Column(
children: [
const Expanded(
flex: 6, child: TodoListWidget()),
const SizedBox(height: 16),
const Expanded(
flex: 3, child: BibleVerseWidget()),
],
),
),
],
),
),

View File

@@ -76,4 +76,22 @@ class PhotoService {
}
await _client.delete("${ApiConfig.photos}/$id");
}
Future<String> getGoogleAuthUrl() async {
final data = await _client.get("${ApiConfig.photos}/auth/url");
return data["url"] as String;
}
Future<bool> getGoogleStatus() async {
try {
final data = await _client.get("${ApiConfig.photos}/status");
return data["connected"] as bool? ?? false;
} catch (e) {
return false;
}
}
Future<void> disconnectGoogle() async {
await _client.get("${ApiConfig.photos}/disconnect");
}
}

View File

@@ -88,7 +88,7 @@ class _AnnouncementWidgetState extends State<AnnouncementWidget> {
padding: const EdgeInsets.all(16),
child: const Center(
child: Text(
'Welcome Home! Have a great day.',
'우리 집에 오신 것을 환영합니다! 좋은 하루 되세요.',
style: TextStyle(color: Colors.white70, fontSize: 18),
),
),

View File

@@ -39,7 +39,7 @@ class _BibleVerseWidgetState extends State<BibleVerseWidget> {
borderRadius: BorderRadius.circular(16),
border: Border.all(color: Colors.white10),
),
padding: const EdgeInsets.all(24),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 20), // Reduced horizontal padding
child: FutureBuilder<BibleVerse>(
future: _verseFuture,
builder: (context, snapshot) {
@@ -65,27 +65,38 @@ class _BibleVerseWidgetState extends State<BibleVerseWidget> {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.format_quote,
color: Color(0xFFBB86FC),
size: 32,
// Quote icon removed as requested
Expanded(
child: Center(
child: FittedBox(
fit: BoxFit.scaleDown,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 600), // Increased width to utilize space
child: Text(
verse.text.replaceAll('\\n', '\n'), // Just handle line breaks, keep original text
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.white,
fontSize: 36,
height: 1.4,
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
const SizedBox(height: 12),
Text(
verse.text,
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Colors.white,
height: 1.5,
fontStyle: FontStyle.italic,
),
),
const SizedBox(height: 8),
Text(
verse.reference,
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
fontWeight: FontWeight.bold,
FittedBox(
fit: BoxFit.scaleDown,
child: Text(
verse.reference,
style: TextStyle(
color: Theme.of(context).colorScheme.primary,
fontSize: 24, // Reduced from 32
fontWeight: FontWeight.bold,
),
),
),
],

View File

@@ -1,9 +1,51 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import '../models/schedule_item.dart';
import '../services/schedule_service.dart';
class CalendarWidget extends StatelessWidget {
class CalendarWidget extends StatefulWidget {
const CalendarWidget({super.key});
@override
State<CalendarWidget> createState() => _CalendarWidgetState();
}
class _CalendarWidgetState extends State<CalendarWidget> {
List<ScheduleItem> _schedules = [];
@override
void initState() {
super.initState();
_loadSchedules();
}
Future<void> _loadSchedules() async {
try {
final schedules =
await Provider.of<ScheduleService>(context, listen: false)
.fetchMonthlySchedules();
if (mounted) {
setState(() {
_schedules = schedules;
});
}
} catch (e) {
debugPrint('Error loading schedules: $e');
}
}
bool _hasScheduleOn(DateTime date) {
final checkDate = DateTime(date.year, date.month, date.day);
return _schedules.any((s) {
final start =
DateTime(s.startDate.year, s.startDate.month, s.startDate.day);
final end = DateTime(s.endDate.year, s.endDate.month, s.endDate.day);
return (checkDate.isAtSameMomentAs(start) || checkDate.isAfter(start)) &&
(checkDate.isAtSameMomentAs(end) || checkDate.isBefore(end));
});
}
@override
Widget build(BuildContext context) {
final now = DateTime.now();
@@ -12,19 +54,10 @@ class CalendarWidget extends StatelessWidget {
final daysInMonth = lastDayOfMonth.day;
final startingWeekday = firstDayOfMonth.weekday; // Mon=1, Sun=7
// Simple calendar logic
// We need to pad the beginning with empty slots
// If week starts on Sunday, adjust accordingly. Let's assume Mon start for now or use locale.
// Let's assume standard Sun-Sat or Mon-Sun. Let's go with Sun-Sat for standard calendar view often seen in KR/US.
// DateTime.weekday: Mon=1, Sun=7.
// If we want Sun start: Sun=0, Mon=1...
// Let's adjust so Sunday is first.
int offset = startingWeekday %
7; // If startingWeekday is 7 (Sun), offset is 0. If 1 (Mon), offset is 1.
int offset = startingWeekday % 7;
return Container(
padding: const EdgeInsets.all(16),
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Theme.of(context).cardTheme.color,
borderRadius: BorderRadius.circular(16),
@@ -32,38 +65,45 @@ class CalendarWidget extends StatelessWidget {
child: Column(
children: [
// Header
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
DateFormat('MMMM yyyy').format(now),
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
const Icon(Icons.calendar_today, color: Colors.white54),
],
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
DateFormat('yyyy년 M월').format(now),
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 20,
),
),
const Icon(Icons.calendar_today,
color: Colors.white54, size: 20),
],
),
),
const SizedBox(height: 16),
const SizedBox(height: 8),
// Days Header
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: ['S', 'M', 'T', 'W', 'T', 'F', 'S'].map((day) {
children: ['', '', '', '', '', '', ''].asMap().entries.map((entry) {
final isSunday = entry.key == 0;
return Expanded(
child: Center(
child: Text(
day,
style: const TextStyle(
color: Colors.white54,
entry.value,
style: TextStyle(
color: isSunday ? Colors.redAccent : Colors.white54,
fontWeight: FontWeight.bold,
fontSize: 14,
),
),
),
);
}).toList(),
),
const SizedBox(height: 8),
const SizedBox(height: 4),
// Days Grid
Expanded(
child: Column(
@@ -73,36 +113,60 @@ class CalendarWidget extends StatelessWidget {
children: List.generate(7, (col) {
final index = row * 7 + col;
final dayNumber = index - offset + 1;
final isSunday = col == 0;
if (dayNumber < 1 || dayNumber > daysInMonth) {
return const Expanded(child: SizedBox.shrink());
}
final dayDate =
DateTime(now.year, now.month, dayNumber);
final isToday = dayNumber == now.day;
final hasSchedule = _hasScheduleOn(dayDate);
return Expanded(
child: Container(
margin: const EdgeInsets.all(2),
margin: const EdgeInsets.all(1),
decoration: isToday
? BoxDecoration(
color: Theme.of(context).colorScheme.primary,
border: Border.all(
color: Theme.of(context).colorScheme.primary,
width: 2,
),
shape: BoxShape.circle,
)
: null,
child: Center(
child: FittedBox(
fit: BoxFit.scaleDown,
child: Text(
'$dayNumber',
style: TextStyle(
color: isToday ? Colors.black : Colors.white,
fontWeight: isToday
? FontWeight.bold
: FontWeight.normal,
fontSize: 12,
child: Stack(
alignment: Alignment.center,
children: [
Center(
child: FittedBox(
fit: BoxFit.scaleDown,
child: Text(
'$dayNumber',
style: TextStyle(
color: isToday
? Theme.of(context).colorScheme.primary
: (isSunday ? Colors.redAccent : Colors.white),
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
),
),
),
if (hasSchedule) // Show indicator even if it's today
Positioned(
bottom: 2,
child: Container(
width: 14,
height: 4,
decoration: BoxDecoration(
color: Colors.yellowAccent,
borderRadius: BorderRadius.circular(2),
),
),
),
],
),
),
);

View File

@@ -73,7 +73,7 @@ class _ScheduleListWidgetState extends State<ScheduleListWidget> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Weekly Schedule',
'주간 일정',
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: Colors.white,
fontWeight: FontWeight.bold,
@@ -102,17 +102,31 @@ class _ScheduleListWidgetState extends State<ScheduleListWidget> {
);
}
if (_schedules.isEmpty) {
// Correctly filter for current week (Sunday to Saturday)
final now = DateTime.now();
final today = DateTime(now.year, now.month, now.day);
// In Dart, weekday is 1 (Mon) to 7 (Sun).
// To get Sunday: if Mon(1), subtract 1. if Sun(7), subtract 0.
final daysToSubtract = now.weekday % 7;
final startOfWeek = today.subtract(Duration(days: daysToSubtract));
final endOfWeek = startOfWeek.add(const Duration(days: 6, hours: 23, minutes: 59, seconds: 59));
final filteredSchedules = _schedules.where((item) {
// Overlap check: schedule starts before week ends AND schedule ends after week starts
return item.startDate.isBefore(endOfWeek) && item.endDate.isAfter(startOfWeek);
}).toList();
if (filteredSchedules.isEmpty) {
return const Center(
child: Text(
'No schedules this week',
'이번 주 일정이 없습니다',
style: TextStyle(color: Colors.white54),
),
);
}
// Sort by date
final sortedSchedules = List<ScheduleItem>.from(_schedules);
final sortedSchedules = List<ScheduleItem>.from(filteredSchedules);
sortedSchedules.sort((a, b) => a.startDate.compareTo(b.startDate));
return ListView.separated(
@@ -121,41 +135,56 @@ class _ScheduleListWidgetState extends State<ScheduleListWidget> {
const Divider(color: Colors.white10),
itemBuilder: (context, index) {
final item = sortedSchedules[index];
final timeStr = item.isAllDay
? 'All Day'
: DateFormat('HH:mm').format(item.startDate);
// Multi-day check
final isMultiDay = item.startDate.year != item.endDate.year ||
item.startDate.month != item.endDate.month ||
item.startDate.day != item.endDate.day;
String? dateRangeStr;
if (isMultiDay) {
final startStr = DateFormat('MM/dd').format(item.startDate);
final endStr = DateFormat('MM/dd').format(item.endDate);
dateRangeStr = '$startStr ~ $endStr';
}
return ListTile(
contentPadding: EdgeInsets.zero,
leading: Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
horizontal: 10,
vertical: 6,
),
decoration: BoxDecoration(
color: Colors.white10,
color: isMultiDay ? Colors.blue.withOpacity(0.2) : Colors.white10,
borderRadius: BorderRadius.circular(8),
border: isMultiDay ? Border.all(color: Colors.blue.withOpacity(0.5)) : null,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Text(
DateFormat('d').format(item.startDate),
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18,
child: FittedBox(
fit: BoxFit.scaleDown,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Text(
DateFormat('d').format(item.startDate),
style: TextStyle(
color: isMultiDay ? Colors.blue : Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18,
height: 1.2,
),
),
),
Text(
DateFormat('E').format(item.startDate),
style: const TextStyle(
color: Colors.white70,
fontSize: 12,
Text(
DateFormat('E').format(item.startDate),
style: const TextStyle(
color: Colors.white70,
fontSize: 12,
height: 1.2,
),
),
),
],
],
),
),
),
title: Text(
@@ -165,10 +194,15 @@ class _ScheduleListWidgetState extends State<ScheduleListWidget> {
fontWeight: FontWeight.w500,
),
),
subtitle: Text(
timeStr,
style: const TextStyle(color: Colors.white54),
),
subtitle: dateRangeStr != null
? Text(
dateRangeStr,
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
)
: null,
);
},
);

View File

@@ -1,5 +1,6 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import '../models/todo_item.dart';
import '../models/family_member.dart';
@@ -85,7 +86,7 @@ class _TodoListWidgetState extends State<TodoListWidget> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Today's Todos",
"오늘의 할 일",
style: Theme.of(context).textTheme.titleLarge?.copyWith(
color: Colors.white,
fontWeight: FontWeight.bold,
@@ -128,7 +129,7 @@ class _TodoListWidgetState extends State<TodoListWidget> {
Icon(Icons.thumb_up, color: Colors.white24, size: 32),
SizedBox(height: 8),
Text(
'All done for today!',
'오늘 할 일을 모두 마쳤습니다!',
style: TextStyle(color: Colors.white54),
),
],
@@ -218,6 +219,12 @@ class _TodoListWidgetState extends State<TodoListWidget> {
decorationColor: Colors.white54,
),
),
subtitle: todo.dueDate != null && (todo.dueDate!.hour != 0 || todo.dueDate!.minute != 0)
? Text(
DateFormat('HH:mm').format(todo.dueDate!),
style: const TextStyle(color: Colors.white54, fontSize: 12),
)
: null,
trailing: Checkbox(
value: todo.completed,
onChanged: (val) async {

View File

@@ -1,3 +1,4 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter/foundation.dart';
@@ -32,65 +33,6 @@ class _WeatherWidgetState extends State<WeatherWidget> {
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>(
@@ -100,116 +42,133 @@ class _WeatherWidgetState extends State<WeatherWidget> {
).fetchWeather(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(
child: SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(strokeWidth: 2),
),
);
return const SizedBox.shrink();
}
if (snapshot.hasError) {
debugPrint('Weather Error: ${snapshot.error}');
return const Text(
'Weather Unavailable',
style: TextStyle(color: Colors.white54),
);
}
if (!snapshot.hasData) {
if (snapshot.hasError || !snapshot.hasData) {
return const SizedBox.shrink();
}
final weather = snapshot.data!;
// Assuming OpenWeatherMap icon format
final iconUrl = (ApiConfig.useMockData || kIsWeb)
? null
: (weather.icon.isNotEmpty
? "https://openweathermap.org/img/wn/${weather.icon}@2x.png"
: null);
final weatherIcon = _getWeatherIcon(weather.icon);
return Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// Weather Icon
if (iconUrl != null)
Image.network(
iconUrl,
width: 72,
height: 72,
errorBuilder: (_, __, ___) =>
const Icon(Icons.wb_sunny, color: Colors.amber),
)
else
const Icon(Icons.wb_sunny, color: Colors.amber, size: 60),
const SizedBox(width: 16),
return Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.5),
borderRadius: BorderRadius.circular(24),
border: Border.all(color: Colors.white24, width: 1.5),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
// 1. Weather Icon (Material Icon)
Icon(
weatherIcon.icon,
color: weatherIcon.color,
size: 40,
),
// Temperature & City info
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
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: 16),
// 2. Temperatures
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// Current
Text(
'${weather.temperature.round()}°',
style: const TextStyle(
fontSize: 42, // Reduced from 54
fontWeight: FontWeight.bold,
color: Colors.white,
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
),
),
],
),
const SizedBox(width: 20),
// Max
const Text('', style: TextStyle(color: Colors.redAccent, fontSize: 16)),
Text(
'${weather.tempMax.round()}°',
style: const TextStyle(
fontSize: 26,
fontWeight: FontWeight.bold,
color: Colors.white, // Reverted to white
),
],
),
),
const SizedBox(width: 12),
// Min
const Text('', style: TextStyle(color: Colors.lightBlueAccent, fontSize: 16)),
Text(
'${weather.tempMin.round()}°',
style: const TextStyle(
fontSize: 26,
fontWeight: FontWeight.bold,
color: Colors.white, // Reverted to white
),
),
],
),
// 3. AQI
if (weather.aqi > 0) ...[
const SizedBox(width: 24),
Container(width: 2, height: 36, color: Colors.white24),
const SizedBox(width: 24),
_buildAqiBadge(weather.aqi),
],
),
// 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),
),
],
],
),
);
},
);
}
// Helper to map OWM icon codes to Material Icons
({IconData icon, Color color}) _getWeatherIcon(String iconCode) {
// Standard OWM codes: https://openweathermap.org/weather-conditions
if (iconCode.startsWith('01')) { // Clear sky
return (icon: Icons.sunny, color: Colors.amber);
} else if (iconCode.startsWith('02') || iconCode.startsWith('03') || iconCode.startsWith('04')) { // Clouds
return (icon: Icons.cloud, color: Colors.white70);
} else if (iconCode.startsWith('09') || iconCode.startsWith('10')) { // Rain
return (icon: Icons.umbrella, color: Colors.blueAccent);
} else if (iconCode.startsWith('11')) { // Thunderstorm
return (icon: Icons.thunderstorm, color: Colors.yellow);
} else if (iconCode.startsWith('13')) { // Snow
return (icon: Icons.ac_unit, color: Colors.lightBlueAccent);
} else if (iconCode.startsWith('50')) { // Mist/Fog
return (icon: Icons.waves, color: Colors.white54);
}
return (icon: Icons.wb_sunny, color: Colors.amber); // Fallback
}
Widget _buildAqiBadge(int aqi) {
Color color;
IconData icon;
String label;
switch (aqi) {
case 1: color = Colors.blue; icon = Icons.sentiment_very_satisfied; label = "좋음"; break;
case 2: color = Colors.green; icon = Icons.sentiment_satisfied; label = "보통"; break;
case 3: color = Colors.yellow[700]!; icon = Icons.sentiment_neutral; label = "주의"; break;
case 4: color = Colors.orange; icon = Icons.sentiment_dissatisfied; label = "나쁨"; break;
case 5: color = Colors.red; icon = Icons.sentiment_very_dissatisfied; label = "매우 나쁨"; break;
default: return const SizedBox.shrink();
}
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(icon, color: color, size: 36),
const SizedBox(width: 10),
Text(
label,
style: TextStyle(color: color, fontSize: 24, fontWeight: FontWeight.bold),
),
],
);
}
}

View File

@@ -405,6 +405,70 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.4.0"
url_launcher:
dependency: "direct main"
description:
name: url_launcher
sha256: f6a7e5c4835bb4e3026a04793a4199ca2d14c739ec378fdfe23fc8075d0439f8
url: "https://pub.dev"
source: hosted
version: "6.3.2"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
sha256: "767344bf3063897b5cf0db830e94f904528e6dd50a6dfaf839f0abf509009611"
url: "https://pub.dev"
source: hosted
version: "6.3.28"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
sha256: cfde38aa257dae62ffe79c87fab20165dfdf6988c1d31b58ebf59b9106062aad
url: "https://pub.dev"
source: hosted
version: "6.3.6"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: d5e14138b3bc193a0f63c10a53c94b91d399df0512b1f29b94a043db7482384a
url: "https://pub.dev"
source: hosted
version: "3.2.2"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
sha256: "368adf46f71ad3c21b8f06614adb38346f193f3a59ba8fe9a2fd74133070ba18"
url: "https://pub.dev"
source: hosted
version: "3.2.5"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "552f8a1e663569be95a8190206a38187b531910283c3e982193e4f2733f01029"
url: "https://pub.dev"
source: hosted
version: "2.3.2"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: d0412fcf4c6b31ecfdb7762359b7206ffba3bbffd396c6d9f9c4616ece476c1f
url: "https://pub.dev"
source: hosted
version: "2.4.2"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: "712c70ab1b99744ff066053cbe3e80c73332b38d46e5e945c98689b2e66fc15f"
url: "https://pub.dev"
source: hosted
version: "3.1.5"
vector_math:
dependency: transitive
description:

View File

@@ -15,6 +15,7 @@ dependencies:
provider: ^6.1.2
google_fonts: ^6.1.0
file_picker: ^8.0.5
url_launcher: ^6.3.2
dev_dependencies:
flutter_test: