2024-12-21 19:41:00 +01:00
|
|
|
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<HomePage> {
|
|
|
|
int _selectedIndex = 0;
|
|
|
|
|
|
|
|
// Define the pages for each section
|
|
|
|
final List<Widget> _pages = [
|
2024-12-22 20:35:58 +01:00
|
|
|
LeaderboardPage(),
|
|
|
|
JoinMatchPage(),
|
|
|
|
CreateMatchPage(),
|
|
|
|
AddFriendPage(),
|
|
|
|
ProfilePage(),
|
2024-12-21 19:41:00 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
void _onBottomNavTap(int index) {
|
|
|
|
setState(() {
|
|
|
|
_selectedIndex = index;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _logout(BuildContext context) async {
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
2024-12-22 20:35:58 +01:00
|
|
|
await prefs.remove('token');
|
2024-12-21 19:41:00 +01:00
|
|
|
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',
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2024-12-22 20:35:58 +01:00
|
|
|
body: _pages[_selectedIndex],
|
2024-12-21 19:41:00 +01:00
|
|
|
bottomNavigationBar: BottomNavigationBarCustom(
|
|
|
|
currentIndex: _selectedIndex,
|
|
|
|
onTap: _onBottomNavTap,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|