MIF_E31230892/sim_mobile/lib/features/main_shell.dart

105 lines
2.9 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// lib/features/main_shell.dart
// Bottom Navigation wrapper keeps each tab alive via IndexedStack.
import 'package:flutter/material.dart';
import 'dashboard/dashboard_page.dart';
import 'capaian/presentation/pages/capaian_page.dart';
import 'berita/berita_page.dart';
import 'profil/profil_page.dart';
const _kPrimary = Color(0xFF6FBA9D);
class MainShell extends StatefulWidget {
const MainShell({super.key});
@override
State<MainShell> createState() => _MainShellState();
}
class _MainShellState extends State<MainShell> {
int _currentIndex = 0;
final _pages = const [
DashboardPage(),
CapaianPage(),
BeritaPage(),
ProfilPage(),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(
index: _currentIndex,
children: _pages,
),
bottomNavigationBar: Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.06),
blurRadius: 10,
offset: const Offset(0, -2),
),
],
),
child: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_navItem(Icons.home_rounded, 'Home', 0),
_navItem(Icons.emoji_events_rounded, 'Capaian', 1),
_navItem(Icons.article_rounded, 'Berita', 2),
_navItem(Icons.person_rounded, 'Profil', 3),
],
),
),
),
),
);
}
Widget _navItem(IconData icon, String label, int index) {
final isActive = _currentIndex == index;
return GestureDetector(
onTap: () => setState(() => _currentIndex = index),
behavior: HitTestBehavior.opaque,
child: AnimatedContainer(
duration: const Duration(milliseconds: 200),
padding: EdgeInsets.symmetric(
horizontal: isActive ? 16 : 12,
vertical: 8,
),
decoration: BoxDecoration(
color: isActive ? _kPrimary.withValues(alpha: 0.12) : Colors.transparent,
borderRadius: BorderRadius.circular(12),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
icon,
size: 22,
color: isActive ? _kPrimary : Colors.grey[400],
),
if (isActive) ...[
const SizedBox(width: 6),
Text(
label,
style: const TextStyle(
color: _kPrimary,
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
],
],
),
),
);
}
}