161 lines
5.2 KiB
Dart
161 lines
5.2 KiB
Dart
// main.dart
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
// 새로 만든 페이지 파일들을 import 합니다.
|
|
import 'home_page.dart'; // HomePage에 콜백을 전달해야 하므로 import 경로 확인
|
|
import 'plan_page.dart';
|
|
import 'statistics_page.dart';
|
|
import 'more_page.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 {
|
|
const MyHomePage({super.key});
|
|
|
|
@override
|
|
State<MyHomePage> createState() => _MyHomePageState();
|
|
}
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
|
int _selectedIndex = 0;
|
|
|
|
// 각 탭에 연결될 페이지 위젯 리스트
|
|
// HomePage는 StatefulWidget이므로 const를 붙이지 않습니다.
|
|
// *** 수정: _widgetOptions를 late로 선언하고 initState에서 초기화 ***
|
|
late final List<Widget> _widgetOptions;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// *** 수정: HomePage 생성 시 onNavigateToPlanTab 콜백 전달 ***
|
|
_widgetOptions = <Widget>[
|
|
HomePage(onNavigateToPlanTab: _onItemTapped), // 콜백 함수 전달
|
|
const PlanPage(),
|
|
const StatisticsPage(),
|
|
const MorePage(),
|
|
];
|
|
}
|
|
|
|
void _onItemTapped(int index) {
|
|
setState(() {
|
|
_selectedIndex = index;
|
|
});
|
|
// 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 = 'More';
|
|
}
|
|
|
|
// --- BottomNavigationBar 크기 및 스타일 설정 ---
|
|
const double customBottomNavHeight = 75.0; // 원하는 BottomNavigationBar 높이
|
|
const double customBottomNavIconSize = 22.0; // 내부 아이콘 크기 (선택적 조절)
|
|
const double customBottomNavSelectedFontSize = 12.0; // 선택된 레이블 폰트 크기 (선택적 조절)
|
|
const double customBottomNavUnselectedFontSize = 10.0; // 미선택 레이블 폰트 크기 (선택적 조절)
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
toolbarHeight: 40,
|
|
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
title: Text(appBarTitle), // 동적으로 변경된 AppBar 제목
|
|
actions: <Widget>[
|
|
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: SizedBox(
|
|
height: customBottomNavHeight,
|
|
child: BottomNavigationBar(
|
|
items: const <BottomNavigationBarItem>[
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.home_filled),
|
|
label: 'Home',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.calendar_today_outlined),
|
|
label: 'Plan',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.bar_chart_outlined),
|
|
label: 'Statistics',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.more_horiz_outlined),
|
|
label: 'More',
|
|
),
|
|
],
|
|
currentIndex: _selectedIndex,
|
|
selectedItemColor: Colors.amber[800],
|
|
unselectedItemColor: Colors.blue,
|
|
onTap: _onItemTapped,
|
|
type: BottomNavigationBarType.fixed,
|
|
iconSize: customBottomNavIconSize,
|
|
selectedFontSize: customBottomNavSelectedFontSize,
|
|
unselectedFontSize: customBottomNavUnselectedFontSize,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |