100 lines
2.9 KiB
Dart
100 lines
2.9 KiB
Dart
import 'package:apkcoba/notifikasi_page.dart';
|
|
import 'package:apkcoba/profile_page.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:firebase_auth/firebase_auth.dart';
|
|
import 'package:firebase_database/firebase_database.dart';
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
import 'dart:async';
|
|
|
|
import 'home_screen.dart';
|
|
import 'history_page.dart';
|
|
import 'notifikasi_page.dart';
|
|
import 'profile_page.dart';
|
|
import 'notifikasi_service.dart';
|
|
|
|
class MainNavigation extends StatefulWidget {
|
|
final int currentIndex;
|
|
const MainNavigation({super.key, this.currentIndex = 0});
|
|
|
|
@override
|
|
_MainNavigationState createState() => _MainNavigationState();
|
|
}
|
|
|
|
class _MainNavigationState extends State<MainNavigation> {
|
|
late int _selectedIndex;
|
|
final bool _hasSentKotak1 = false;
|
|
final bool _hasSentKotak2 = false;
|
|
DateTime? _lastSentKotak1;
|
|
DateTime? _lastSentKotak2;
|
|
static const Duration minInterval = Duration(seconds: 10);
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
//syncTimestampIfAuthorized();
|
|
//NotifikasiService.listenToAllNotifikasi();
|
|
_selectedIndex = widget.currentIndex; // <== GUNAKAN INI!
|
|
}
|
|
|
|
final List<Widget> _pages = [
|
|
HomeScreen(username: '', onSignOut: () {}),
|
|
HistoryPage(),
|
|
NotifikasiPage(), // Notification
|
|
ProfilePage(), // Account
|
|
];
|
|
|
|
void _onItemTapped(int index) {
|
|
setState(() {
|
|
_selectedIndex = index;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: _pages[_selectedIndex],
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
currentIndex: _selectedIndex,
|
|
onTap: _onItemTapped,
|
|
type: BottomNavigationBarType.fixed, // stabil untuk banyak item
|
|
selectedItemColor: const Color(0xFF3FA535),
|
|
unselectedItemColor: Colors.grey.shade600,
|
|
showUnselectedLabels: true,
|
|
selectedLabelStyle: const TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
fontSize: 14,
|
|
),
|
|
unselectedLabelStyle: const TextStyle(
|
|
fontWeight: FontWeight.normal,
|
|
fontSize: 12,
|
|
),
|
|
elevation: 8,
|
|
backgroundColor: Colors.white,
|
|
iconSize: 28,
|
|
items: const [
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.home_outlined),
|
|
activeIcon: Icon(Icons.home),
|
|
label: 'Home',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.history_outlined),
|
|
activeIcon: Icon(Icons.history),
|
|
label: 'History',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.notifications_outlined),
|
|
activeIcon: Icon(Icons.notifications),
|
|
label: 'Notification',
|
|
),
|
|
BottomNavigationBarItem(
|
|
icon: Icon(Icons.person_outline),
|
|
activeIcon: Icon(Icons.person),
|
|
label: 'Account',
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|