dth-pingpong-mobileapp/lib/pages/home.dart
2024-12-22 20:35:58 +01:00

64 lines
1.5 KiB
Dart

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 = [
LeaderboardPage(),
JoinMatchPage(),
CreateMatchPage(),
AddFriendPage(),
ProfilePage(),
];
void _onBottomNavTap(int index) {
setState(() {
_selectedIndex = index;
});
}
Future<void> _logout(BuildContext context) async {
final prefs = await SharedPreferences.getInstance();
await prefs.remove('token');
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],
bottomNavigationBar: BottomNavigationBarCustom(
currentIndex: _selectedIndex,
onTap: _onBottomNavTap,
),
);
}
}