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';
|
2024-12-25 12:08:09 +01:00
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'dart:convert';
|
|
|
|
import '../globals.dart';
|
2024-12-21 19:41:00 +01:00
|
|
|
|
|
|
|
class HomePage extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_HomePageState createState() => _HomePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _HomePageState extends State<HomePage> {
|
|
|
|
int _selectedIndex = 0;
|
|
|
|
|
|
|
|
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-25 12:08:09 +01:00
|
|
|
Future<Map<String, String>> fetchCommitHashes() async {
|
2025-01-14 00:15:19 +01:00
|
|
|
const apiUrl = '$apiurl/version';
|
2024-12-25 12:08:09 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
final response = await http.get(Uri.parse(apiUrl));
|
|
|
|
|
|
|
|
if (response.statusCode == 200) {
|
|
|
|
final data = jsonDecode(response.body);
|
|
|
|
|
|
|
|
String formatHash(String? hash) {
|
|
|
|
if (hash == null) return 'Unknown';
|
|
|
|
return '#${hash.substring(0, 8).toUpperCase()}';
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
'backend': formatHash(data['backend']),
|
|
|
|
'frontend': formatHash(data['frontend']),
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
throw Exception('Failed to fetch commit hashes');
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
return {
|
|
|
|
'backend': 'Error fetching hash',
|
|
|
|
'frontend': 'Error fetching hash',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-23 22:10:06 +01:00
|
|
|
Future<void> _showOpenSourceLicenses() async {
|
2024-12-25 12:08:09 +01:00
|
|
|
final commitHashes = await fetchCommitHashes();
|
|
|
|
|
2024-12-23 22:10:06 +01:00
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) => AboutDialog(
|
|
|
|
applicationIcon: const Icon(Icons.code),
|
|
|
|
applicationLegalese: '© 2024 Thomas Bassi @ Defence Tech.',
|
|
|
|
applicationName: 'DTHPP',
|
2024-12-25 12:08:09 +01:00
|
|
|
applicationVersion:
|
|
|
|
'API: ${commitHashes['backend']} - UI: ${commitHashes['frontend']}',
|
2024-12-23 22:10:06 +01:00
|
|
|
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,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|