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'; import 'package:http/http.dart' as http; import 'dart:convert'; import '../globals.dart'; class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State { int _selectedIndex = 0; final List _pages = [ LeaderboardPage(), JoinMatchPage(), CreateMatchPage(), AddFriendPage(), ProfilePage(), ]; void _onBottomNavTap(int index) { setState(() { _selectedIndex = index; }); } Future _logout(BuildContext context) async { final prefs = await SharedPreferences.getInstance(); await prefs.remove('token'); Navigator.pushReplacement( context, MaterialPageRoute(builder: (context) => LoginPage()), ); } Future> fetchCommitHashes() async { const apiUrl = '$apiurl/version'; 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', }; } } Future _showOpenSourceLicenses() async { final commitHashes = await fetchCommitHashes(); showDialog( context: context, builder: (BuildContext context) => AboutDialog( applicationIcon: const Icon(Icons.code), applicationLegalese: '© 2024 Thomas Bassi @ Defence Tech.', applicationName: 'DTHPP', applicationVersion: 'API: ${commitHashes['backend']} - UI: ${commitHashes['frontend']}', 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), ), ), ], ), ); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Ping Pong Tracker'), actions: [ IconButton( icon: Icon(Icons.info), onPressed: _showOpenSourceLicenses, tooltip: 'Open Source Licenses', ), IconButton( icon: Icon(Icons.logout), onPressed: () => _logout(context), tooltip: 'Logout', ), ], ), body: _pages[_selectedIndex], bottomNavigationBar: BottomNavigationBarCustom( currentIndex: _selectedIndex, onTap: _onBottomNavTap, ), ); } }