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()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-12-23 22:10:06 +01:00
|
|
|
Future<void> _showOpenSourceLicenses() async {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) => AboutDialog(
|
|
|
|
applicationIcon: const Icon(Icons.code),
|
|
|
|
applicationLegalese: '© 2024 Thomas Bassi @ Defence Tech.',
|
|
|
|
applicationName: 'DTHPP',
|
|
|
|
applicationVersion: '#B22AF349A1',
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 16.0),
|
|
|
|
child: Text(
|
|
|
|
"Do people even care about licenses? Is this ever going to be opened? Anywho, i hope you're enjoying the app and having fun on your break :D",
|
|
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w400),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-12-21 19:41:00 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
|
|
|
title: Text('Ping Pong Tracker'),
|
|
|
|
actions: [
|
2024-12-23 22:10:06 +01:00
|
|
|
IconButton(
|
|
|
|
icon: Icon(Icons.info),
|
|
|
|
onPressed: _showOpenSourceLicenses,
|
|
|
|
tooltip: 'Open Source Licenses',
|
|
|
|
),
|
2024-12-21 19:41:00 +01:00
|
|
|
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,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|