101 lines
2.3 KiB
Dart
101 lines
2.3 KiB
Dart
import 'package:fitnote/layout/app_navbar.dart';
|
|
import 'package:fitnote/modesl/menu.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class HomePage extends StatefulWidget {
|
|
const HomePage({super.key});
|
|
|
|
@override
|
|
_HomePageState createState() => _HomePageState();
|
|
}
|
|
|
|
class _HomePageState extends State<HomePage> {
|
|
int _currentPageIndex = 0;
|
|
late PageController _pageController;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_pageController = PageController(initialPage: _currentPageIndex);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_pageController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
Widget _buildLeading() {
|
|
return Builder(
|
|
builder:
|
|
(context) => IconButton(
|
|
icon: Icon(Icons.menu, color: Colors.white),
|
|
onPressed: () => Scaffold.of(context).openDrawer(),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildAppBarTitle() {
|
|
return Text(
|
|
pages[_currentPageIndex].title,
|
|
style: TextStyle(color: Colors.white),
|
|
);
|
|
}
|
|
|
|
Widget _buildPageView() {
|
|
return PageView(
|
|
controller: _pageController,
|
|
onPageChanged: (index) {
|
|
setState(() {
|
|
_currentPageIndex = index;
|
|
});
|
|
},
|
|
children: pageWidgets,
|
|
);
|
|
}
|
|
|
|
void _onTapNavbarItem(int index) {
|
|
setState(() {
|
|
_currentPageIndex = index;
|
|
});
|
|
_pageController.animateToPage(
|
|
index,
|
|
duration: Duration(milliseconds: 300),
|
|
curve: Curves.easeInOut,
|
|
);
|
|
}
|
|
|
|
void onTapDrawerItem(int index) {
|
|
setState(() {
|
|
_currentPageIndex = index;
|
|
});
|
|
_pageController.animateToPage(
|
|
index,
|
|
duration: Duration(milliseconds: 300),
|
|
curve: Curves.easeInOut,
|
|
);
|
|
Navigator.pop(context);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: _buildAppBarTitle(),
|
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
|
elevation: 0,
|
|
leading: _buildLeading(),
|
|
),
|
|
// drawer: AppDrawer(
|
|
// currentPageIndex: _currentPageIndex,
|
|
// onTapDrawerItem: onTapDrawerItem,
|
|
// ),
|
|
body: Padding(padding: EdgeInsets.all(10), child: _buildPageView()),
|
|
bottomNavigationBar: AppNavbar(
|
|
currentPageIndex: _currentPageIndex,
|
|
onTapNavbarItem: _onTapNavbarItem,
|
|
),
|
|
);
|
|
}
|
|
}
|