한번 좆되서 다시 돌림
This commit is contained in:
@@ -2,8 +2,9 @@ import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
import 'youtube_player_page.dart'; // YoutubePlayerPage import
|
||||
import 'common/widgets/custom_bottom_nav_bar.dart';
|
||||
|
||||
// PlanDetailItem 클래스
|
||||
// PlanDetailItem 클래스 (이전과 동일)
|
||||
class PlanDetailItem {
|
||||
final String lessonId;
|
||||
final String lessonTag;
|
||||
@@ -27,62 +28,82 @@ class PlanDetailItem {
|
||||
}
|
||||
}
|
||||
|
||||
class plan_page_detail extends StatefulWidget {
|
||||
// final int currentBottomNavIndex; // HomePage 등에서 전달받을 현재 탭 인덱스
|
||||
|
||||
const plan_page_detail({
|
||||
class PlanPageDetail extends StatefulWidget {
|
||||
const PlanPageDetail({
|
||||
super.key,
|
||||
// this.currentBottomNavIndex = 0, // 기본값
|
||||
});
|
||||
|
||||
@override
|
||||
State<plan_page_detail> createState() => _plan_page_detailState();
|
||||
State<PlanPageDetail> createState() => _PlanPageDetailState();
|
||||
}
|
||||
|
||||
class _plan_page_detailState extends State<plan_page_detail> {
|
||||
class _PlanPageDetailState extends State<PlanPageDetail> {
|
||||
String? _planId;
|
||||
String? _planTitle; // <<< planTitle을 저장할 상태 변수 추가 >>>
|
||||
Future<List<PlanDetailItem>>? _planDetails;
|
||||
late int _currentBottomNavIndex; // 하단 네비게이션 바 상태
|
||||
late int _currentBottomNavIndex;
|
||||
String? _selectedYoutubeUrl;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 이전 페이지에서 전달받은 탭 인덱스로 초기화하거나 기본값 사용
|
||||
// _currentBottomNavIndex = widget.currentBottomNavIndex;
|
||||
_currentBottomNavIndex = 0; // 예시: '홈' 탭을 기본으로 설정
|
||||
_currentBottomNavIndex = 0;
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
if (_planId == null) {
|
||||
// 인자를 한 번만 처리하도록 조건 추가
|
||||
if (_planId == null && _planTitle == null) {
|
||||
final Object? arguments = ModalRoute.of(context)?.settings.arguments;
|
||||
if (arguments is String) {
|
||||
_planId = arguments;
|
||||
if (arguments is Map<String, String>) { // <<< 전달받은 인자가 Map인지 확인 >>>
|
||||
setState(() { // <<< setState로 상태 변수 업데이트 >>>
|
||||
_planId = arguments['planId'];
|
||||
_planTitle = arguments['planTitle'];
|
||||
});
|
||||
|
||||
if (_planId != null) {
|
||||
_planDetails = _fetchPlanDetails(_planId!);
|
||||
} else {
|
||||
// Map에는 있지만 planId 키가 없는 경우 (이론상 발생하기 어려움)
|
||||
setState(() {
|
||||
_planTitle = arguments['planTitle'] ?? 'Error'; // planTitle은 있을 수 있음
|
||||
});
|
||||
_planDetails =
|
||||
Future.error(Exception("Plan ID가 Map에 포함되지 않았습니다."));
|
||||
|
||||
}
|
||||
} else {
|
||||
_planDetails = Future.error(Exception("Plan ID not provided or invalid."));
|
||||
print("Error: Plan ID not provided or invalid.");
|
||||
// 인자가 Map이 아니거나 null인 경우
|
||||
setState(() {
|
||||
_planTitle = 'Error'; // AppBar에 오류 표시
|
||||
});
|
||||
_planDetails =
|
||||
Future.error(Exception("전달된 인자가 올바르지 않습니다. (Map<String, String> 형태여야 함)"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<PlanDetailItem>> _fetchPlanDetails(String planId) async {
|
||||
final response = await http
|
||||
.get(Uri.parse('https://helloworld1-ad2uqhckxq-uc.a.run.app/?id=$planId'));
|
||||
final response = await http.get(
|
||||
Uri.parse('https://helloworld1-ad2uqhckxq-uc.a.run.app/?id=$planId'));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final Map<String, dynamic> decodedJson = json.decode(response.body);
|
||||
if (decodedJson.containsKey('data') && decodedJson['data'] is List) {
|
||||
final List<dynamic> detailsJson = decodedJson['data'];
|
||||
return detailsJson.map((jsonItem) => PlanDetailItem.fromJson(jsonItem as Map<String, dynamic>)).toList();
|
||||
return detailsJson
|
||||
.map((jsonItem) =>
|
||||
PlanDetailItem.fromJson(jsonItem as Map<String, dynamic>))
|
||||
.toList();
|
||||
} else {
|
||||
throw Exception('Invalid API response format: "data" field is missing or not a list.');
|
||||
throw Exception(
|
||||
'Invalid API response format: "data" field is missing or not a list.');
|
||||
}
|
||||
} else {
|
||||
throw Exception('Failed to load plan details. Status code: ${response.statusCode}');
|
||||
throw Exception(
|
||||
'Failed to load plan details. Status code: ${response.statusCode}');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,16 +111,26 @@ class _plan_page_detailState extends State<plan_page_detail> {
|
||||
setState(() {
|
||||
_currentBottomNavIndex = index;
|
||||
});
|
||||
// 페이지 이동 로직 (이전 답변 참고)
|
||||
if (index == 0) {
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
} else if (index == 1) {
|
||||
} else {
|
||||
String tabName = '';
|
||||
switch (index) {
|
||||
case 1:
|
||||
tabName = 'Plan';
|
||||
break;
|
||||
case 2:
|
||||
tabName = 'Statistics';
|
||||
break;
|
||||
case 3:
|
||||
tabName = 'Jobs'; // New case for Jobs
|
||||
break;
|
||||
case 4:
|
||||
tabName = 'More'; // Updated case for More
|
||||
break;
|
||||
}
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Search (Not Implemented)')),
|
||||
);
|
||||
} else if (index == 2) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Profile (Not Implemented)')),
|
||||
SnackBar(content: Text('$tabName 탭으로 이동 (구현 필요)')),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -107,17 +138,9 @@ class _plan_page_detailState extends State<plan_page_detail> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
// 1. 상단 바 (AppBar)
|
||||
appBar: AppBar(
|
||||
title: Text(_planId != null ? 'Plan: $_planId' : 'Plan Details'),
|
||||
// 필요하다면 leading에 뒤로가기 버튼 명시적 추가
|
||||
leading: Navigator.canPop(context)
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios_new), // 또는 Icons.arrow_back
|
||||
tooltip: 'Back',
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
)
|
||||
: null,
|
||||
toolbarHeight: 40,
|
||||
title: Text(_planTitle.toString()),
|
||||
),
|
||||
body: _planId == null
|
||||
? const Center(
|
||||
@@ -212,8 +235,10 @@ class _plan_page_detailState extends State<plan_page_detail> {
|
||||
}
|
||||
},
|
||||
),
|
||||
// 2. 하단 바 (BottomNavigationBar)
|
||||
|
||||
bottomNavigationBar: CustomBottomNavBar(
|
||||
currentIndex: _currentBottomNavIndex,
|
||||
onTap: _onBottomNavItemTapped,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user