import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'login.dart'; import '../navbar.dart'; import 'views/leaderboard.dart'; import 'views/joinmatch.dart'; import 'views/creatematch.dart'; import 'views/friendlist.dart'; import 'views/myprofile.dart'; class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State { int _selectedIndex = 0; // Define the pages for each section final List _pages = [ LeaderboardPage(), // Use imported widget JoinMatchPage(), // Use imported widget CreateMatchPage(), // Use imported widget AddFriendPage(), // Use imported widget PlaceholderPage(),//ProfilePage(), // Use imported widget ]; void _onBottomNavTap(int index) { setState(() { _selectedIndex = index; }); } Future _logout(BuildContext context) async { final prefs = await SharedPreferences.getInstance(); await prefs.remove('token'); // Remove the token to log out Navigator.pushReplacement( context, MaterialPageRoute(builder: (context) => LoginPage()), ); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Ping Pong Tracker'), actions: [ IconButton( icon: Icon(Icons.logout), onPressed: () => _logout(context), tooltip: 'Logout', ), ], ), body: _pages[_selectedIndex], // Display the selected page content bottomNavigationBar: BottomNavigationBarCustom( currentIndex: _selectedIndex, onTap: _onBottomNavTap, ), ); } }