import 'package:flutter/material.dart'; import 'dashboard_screen.dart'; import 'chat_list_screen.dart'; import 'more_screen.dart'; import 'settings_screen.dart'; class MainNavigationScreen extends StatefulWidget { const MainNavigationScreen({super.key}); @override State createState() => _MainNavigationScreenState(); } class _MainNavigationScreenState extends State { int _currentIndex = 0; final _dashboardKey = GlobalKey(); late final List _screens; @override void initState() { super.initState(); _screens = [ DashboardScreen(key: _dashboardKey), const ChatListScreen(), const MoreScreen(), const SettingsScreen(), ]; } @override Widget build(BuildContext context) { return Scaffold( body: IndexedStack( index: _currentIndex, children: _screens, ), bottomNavigationBar: NavigationBar( selectedIndex: _currentIndex, onDestinationSelected: (index) { setState(() { _currentIndex = index; }); // Reload preferences whenever switching back to dashboard if (index == 0) { _dashboardKey.currentState?.reloadPreferences(); } }, destinations: const [ NavigationDestination( icon: Icon(Icons.home_outlined), selectedIcon: Icon(Icons.home), label: 'Home', ), NavigationDestination( icon: Icon(Icons.chat_bubble_outline), selectedIcon: Icon(Icons.chat_bubble), label: 'AI Chat', ), NavigationDestination( icon: Icon(Icons.more_horiz), selectedIcon: Icon(Icons.more_horiz), label: 'More', ), NavigationDestination( icon: Icon(Icons.settings_outlined), selectedIcon: Icon(Icons.settings), label: 'Settings', ), ], ), ); } }