132 lines
3.9 KiB
Dart
132 lines
3.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:monitoring_jamur/core/theme/app_theme.dart';
|
|
import 'package:monitoring_jamur/features/home/presentation/pages/dashboard_page.dart';
|
|
import 'package:monitoring_jamur/features/history/presentation/pages/history_page.dart';
|
|
import 'package:monitoring_jamur/features/account/presentation/pages/account_page.dart';
|
|
|
|
class MainScreen extends StatefulWidget {
|
|
const MainScreen({super.key});
|
|
|
|
@override
|
|
State<MainScreen> createState() => _MainScreenState();
|
|
}
|
|
|
|
class _MainScreenState extends State<MainScreen> {
|
|
int _currentIndex = 0;
|
|
final PageController _pageController = PageController();
|
|
|
|
final List<Widget> _pages = [
|
|
const DashboardPage(),
|
|
const HistoryPage(),
|
|
const AccountPage(),
|
|
];
|
|
|
|
void _onItemTapped(int index) {
|
|
if (_currentIndex == index) return;
|
|
setState(() {
|
|
_currentIndex = index;
|
|
});
|
|
_pageController.animateToPage(
|
|
index,
|
|
duration: const Duration(milliseconds: 400),
|
|
curve: Curves.easeInOutCubic,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppTheme.backgroundBeige,
|
|
body: PageView(
|
|
controller: _pageController,
|
|
onPageChanged: (index) {
|
|
setState(() {
|
|
_currentIndex = index;
|
|
});
|
|
},
|
|
children: _pages,
|
|
),
|
|
bottomNavigationBar: _buildAnimatedBottomBar(),
|
|
);
|
|
}
|
|
|
|
Widget _buildAnimatedBottomBar() {
|
|
return Container(
|
|
margin: const EdgeInsets.fromLTRB(16, 0, 16, 24),
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
decoration: BoxDecoration(
|
|
color: AppTheme.surfaceWhite,
|
|
borderRadius: BorderRadius.circular(30),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.08),
|
|
blurRadius: 20,
|
|
offset: const Offset(0, 10),
|
|
),
|
|
],
|
|
),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
_buildNavItem(0, Icons.dashboard_outlined, Icons.dashboard, 'Dashboard'),
|
|
_buildNavItem(1, Icons.history_outlined, Icons.history, 'History'),
|
|
_buildNavItem(2, Icons.person_outline, Icons.person, 'Account'),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildNavItem(int index, IconData outlineIcon, IconData filledIcon, String label) {
|
|
bool isSelected = _currentIndex == index;
|
|
|
|
return GestureDetector(
|
|
onTap: () => _onItemTapped(index),
|
|
behavior: HitTestBehavior.opaque,
|
|
child: AnimatedContainer(
|
|
duration: const Duration(milliseconds: 300),
|
|
curve: Curves.easeOutBack,
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: isSelected ? AppTheme.primaryGreen.withOpacity(0.12) : Colors.transparent,
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
AnimatedScale(
|
|
scale: isSelected ? 1.15 : 1.0,
|
|
duration: const Duration(milliseconds: 300),
|
|
curve: Curves.easeOutBack,
|
|
child: Icon(
|
|
isSelected ? filledIcon : outlineIcon,
|
|
color: isSelected ? AppTheme.primaryGreen : AppTheme.textLight,
|
|
size: 26,
|
|
),
|
|
),
|
|
if (isSelected) ...[
|
|
const SizedBox(width: 8),
|
|
AnimatedOpacity(
|
|
opacity: isSelected ? 1.0 : 0.0,
|
|
duration: const Duration(milliseconds: 300),
|
|
child: Text(
|
|
label,
|
|
style: const TextStyle(
|
|
color: AppTheme.primaryGreen,
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_pageController.dispose();
|
|
super.dispose();
|
|
}
|
|
}
|