일단 잡까지 되는것 저장

This commit is contained in:
girinb
2025-07-11 16:46:23 +09:00
parent 42453abe41
commit 7e56c68827
7 changed files with 265 additions and 183 deletions

View File

@@ -72,8 +72,6 @@ class _HomePageState extends State<HomePage> {
String _currentTimeZone = 'Loading timezone...';
late Stream<DateTime> _clockStream;
int _selectedIndex = 0;
// --- 추천 클래스 관련 상태 변수 ---
List<RecommendPlan> _recommendPlans = [];
int _currentRecommendIndex = 0;
@@ -146,7 +144,6 @@ class _HomePageState extends State<HomePage> {
_currentTimeZone = 'Failed to get timezone.';
});
}
print('Could not get timezone: $e');
}
}
@@ -186,7 +183,6 @@ class _HomePageState extends State<HomePage> {
'Failed to load recommend plans. Status Code: ${response.statusCode}');
}
} catch (e) {
print('Error fetching recommend plans: $e');
if (mounted) {
setState(() {
_isLoadingRecommends = false;
@@ -226,7 +222,7 @@ class _HomePageState extends State<HomePage> {
return Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
color: Theme.of(context).primaryColor.withOpacity(0.1),
color: Theme.of(context).primaryColor.withAlpha(25),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -242,123 +238,6 @@ class _HomePageState extends State<HomePage> {
);
}
// --- 추천 클래스 섹션 위젯 ---
Widget _buildRecommendSection() {
if (_isLoadingRecommends) {
return const Padding(
padding: EdgeInsets.symmetric(vertical: 20.0),
child: Center(child: CircularProgressIndicator()),
);
}
if (_hasRecommendError) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 20.0, horizontal: 16.0),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error_outline, color: Colors.red, size: 40),
const SizedBox(height: 8),
Text(
'Failed to load recommendations.\n$_recommendErrorText',
textAlign: TextAlign.center,
style: const TextStyle(color: Colors.redAccent),
),
const SizedBox(height: 8),
ElevatedButton.icon(
icon: const Icon(Icons.refresh),
label: const Text('Retry'),
onPressed: _fetchRecommendPlans,
)
],
),
),
);
}
if (_recommendPlans.isEmpty) {
return const Padding(
padding: EdgeInsets.symmetric(vertical: 20.0),
child: Center(child: Text('No recommendations available at the moment.')),
);
}
final currentPlan = _recommendPlans[_currentRecommendIndex];
return Container(
margin: const EdgeInsets.fromLTRB(16.0, 12.0, 16.0, 16.0), // 하단 마진 추가
padding: const EdgeInsets.all(12.0),
decoration: BoxDecoration(
color: Theme.of(context).cardColor, // 카드 색상 사용
borderRadius: BorderRadius.circular(12.0),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'✨ Recommend Classes', // 이모지 추가
style: Theme.of(context).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold),
),
const SizedBox(height: 12.0),
Text(
currentPlan.planName,
style: Theme.of(context).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w500),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
// Test: Plan ID 표시 (디버깅용)
// Text('ID: ${currentPlan.planId}', style: TextStyle(fontSize: 10, color: Colors.grey)),
AspectRatio(
aspectRatio: 16 / 9,
child: ClipRRect(
borderRadius: BorderRadius.circular(8.0),
child: currentPlan.thumbnail.isNotEmpty
? Image.network(
currentPlan.thumbnail,
fit: BoxFit.cover,
loadingBuilder: (BuildContext context, Widget child, ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) return child;
return Container( // 로딩 중 배경색 및 인디케이터 중앙 정렬 개선
color: Colors.grey[200],
child: Center(
child: CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded / loadingProgress.expectedTotalBytes!
: null,
),
),
);
},
errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
return Container(
color: Colors.grey[200],
child: const Center(child: Icon(Icons.broken_image, color: Colors.grey, size: 50)),
);
},
)
: Container(
color: Colors.grey[200],
child: const Center(child: Text('No Image Available', style: TextStyle(color: Colors.grey))),
),
),
)],
),
);
}
// --- 추천 클래스 섹션 위젯 끝 ---
Widget _buildHomeContent() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -515,18 +394,6 @@ class _HomePageState extends State<HomePage> {
);
}
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
// 홈 탭(인덱스 0)으로 돌아올 때 추천 타이머를 다시 시작할 수 있도록 고려
if (index == 0 && _recommendPlans.isNotEmpty && (_recommendTimer == null || !_recommendTimer!.isActive)) {
_startRecommendTimer();
} else if (index != 0) {
_recommendTimer?.cancel(); // 다른 탭으로 이동 시 타이머 일시 중지
}
});
}
@override
Widget build(BuildContext context) {
final List<Widget> pageContents = _buildPageContents();
@@ -536,7 +403,7 @@ class _HomePageState extends State<HomePage> {
// title: Text(_selectedIndex == 0 ? 'Home' : 'Plan Page'),
// ),
body: IndexedStack( // AppBar가 없으므로 SafeArea로 감싸는 것을 고려해볼 수 있습니다.
index: _selectedIndex,
index: 0,
children: pageContents,
)
);