// main.dart import 'package:flutter/material.dart'; // 새로 만든 페이지 파일들을 import 합니다. import 'home_page.dart'; // HomePage에 콜백을 전달해야 하므로 import 경로 확인 import 'plan_page.dart'; import 'statistics_page.dart'; import 'career_page.dart'; import 'more_page.dart'; import 'common/widgets/custom_bottom_nav_bar.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( title: 'Case Study', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: const MyHomePage(), ); } } class MyHomePage extends StatefulWidget { final int initialIndex; const MyHomePage({super.key, this.initialIndex = 0}); @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { late int _selectedIndex; // 각 탭에 연결될 페이지 위젯 리스트 // HomePage는 StatefulWidget이므로 const를 붙이지 않습니다. // *** 수정: _widgetOptions를 late로 선언하고 initState에서 초기화 *** late final List _widgetOptions; @override void initState() { super.initState(); _selectedIndex = widget.initialIndex; // *** 수정: HomePage 생성 시 onNavigateToPlanTab 콜백 전달 *** _widgetOptions = [ HomePage(onNavigateToPlanTab: _onItemTapped), // 콜백 함수 전달 const PlanPage(), const StatisticsPage(), const JobsPage(), const MorePage(), ]; } void _onItemTapped(int index) { setState(() { _selectedIndex = index; }); print('Selected index: $_selectedIndex'); // 디버깅 출력 추가 // HomePage의 _recommendTimer 제어 로직은 HomePage 내부에서 독립적으로 관리됩니다. // 또는 필요에 따라 GlobalKey 등을 사용하여 HomePage의 상태에 접근할 수 있습니다. } // 프로필 탭(세 번째 탭, StatisticsPage)으로 이동하는 함수 void _navigateToProfileTab() { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('프로필 눌림')), ); // 필요하다면 여기서 _onItemTapped를 호출하여 특정 탭으로 이동할 수 있습니다. // 예: _onItemTapped(2); // StatisticsPage로 이동 } @override Widget build(BuildContext context) { // AppBar의 제목을 현재 탭에 따라 동적으로 변경 String appBarTitle = 'Home'; // 기본값 if (_selectedIndex == 1) { appBarTitle = 'Plan'; } else if (_selectedIndex == 2) { appBarTitle = 'Statistics'; } else if (_selectedIndex == 3) { appBarTitle = 'Career'; } else if (_selectedIndex == 4) { appBarTitle = 'More'; } return Scaffold( appBar: AppBar( toolbarHeight: 40, backgroundColor: Theme.of(context).colorScheme.inversePrimary, title: Text(appBarTitle), // 동적으로 변경된 AppBar 제목\ actions: [ IconButton( icon: const Icon(Icons.notifications), tooltip: '알림', onPressed: () { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('알림 아이콘 클릭됨')), ); }, ), Padding( padding: const EdgeInsets.only(right: 16.0), child: InkWell( onTap: _navigateToProfileTab, customBorder: const CircleBorder(), child: const CircleAvatar( backgroundColor: Colors.grey, child: Icon( Icons.person, color: Colors.white, ), ), ), ), ], ), body: IndexedStack( // IndexedStack을 사용하여 페이지 상태 유지 index: _selectedIndex, children: _widgetOptions, ), bottomNavigationBar: CustomBottomNavBar( currentIndex: _selectedIndex, onTap: _onItemTapped, ), ); } }