Compare commits

..

No commits in common. "b22af349a1792d495750cd640369e06e608357a3" and "8b9b26ea4ceab3ba9a7d70d079f492415c45a1d8" have entirely different histories.

9 changed files with 236 additions and 244 deletions

View file

@ -1,3 +0,0 @@
// lib/globals.dart
//const String apiurl = "https://api.dthpp.mercurio.moe";
const String apiurl = "http://10.0.0.10:9134";

View file

@ -17,7 +17,7 @@ class MyApp extends StatelessWidget {
title: 'Ping Pong Tracker', title: 'Ping Pong Tracker',
theme: ThemeData.dark(useMaterial3: true).copyWith( theme: ThemeData.dark(useMaterial3: true).copyWith(
colorScheme: ColorScheme.dark( colorScheme: ColorScheme.dark(
primary: Colors.blue.shade800, primary: Colors.blue.shade900,
), ),
), ),
home: EntryPoint(), home: EntryPoint(),

View file

@ -3,7 +3,7 @@ import 'package:shared_preferences/shared_preferences.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'dart:convert'; import 'dart:convert';
import 'home.dart'; import 'home.dart';
import '../globals.dart';
class LoginPage extends StatefulWidget { class LoginPage extends StatefulWidget {
@override @override
@ -18,6 +18,8 @@ class _LoginPageState extends State<LoginPage> {
bool _isLogin = true; bool _isLogin = true;
bool _isLoading = false; bool _isLoading = false;
final String baseUrl = 'http://api.dthpp.mercurio.moe';
Future<void> _handleAuth() async { Future<void> _handleAuth() async {
final email = _emailController.text.trim(); final email = _emailController.text.trim();
final password = _passwordController.text.trim(); final password = _passwordController.text.trim();
@ -36,14 +38,13 @@ class _LoginPageState extends State<LoginPage> {
context, MaterialPageRoute(builder: (context) => HomePage())); context, MaterialPageRoute(builder: (context) => HomePage()));
} }
} else { } else {
final uid = await _register( final uid = await _register(email, password, _displayNameController.text.trim());
email, password, _displayNameController.text.trim());
if (uid != null) { if (uid != null) {
setState(() { setState(() {
_isLogin = true; _isLogin = true;
}); });
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(
content: Text('Registration successful! Please login.'))); SnackBar(content: Text('Registration successful! Please login.')));
} }
} }
} catch (e) { } catch (e) {
@ -57,7 +58,7 @@ class _LoginPageState extends State<LoginPage> {
} }
Future<String?> _login(String email, String password) async { Future<String?> _login(String email, String password) async {
final url = Uri.parse('$apiurl/login'); final url = Uri.parse('$baseUrl/login');
final response = await http.post( final response = await http.post(
url, url,
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
@ -72,9 +73,8 @@ class _LoginPageState extends State<LoginPage> {
} }
} }
Future<String?> _register( Future<String?> _register(String email, String password, String displayName) async {
String email, String password, String displayName) async { final url = Uri.parse('$baseUrl/register');
final url = Uri.parse('$apiurl/register');
final response = await http.post( final response = await http.post(
url, url,
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
@ -121,9 +121,9 @@ class _LoginPageState extends State<LoginPage> {
_isLoading _isLoading
? CircularProgressIndicator() ? CircularProgressIndicator()
: ElevatedButton( : ElevatedButton(
onPressed: _handleAuth, onPressed: _handleAuth,
child: Text(_isLogin ? 'Login' : 'Register'), child: Text(_isLogin ? 'Login' : 'Register'),
), ),
TextButton( TextButton(
onPressed: () { onPressed: () {
setState(() { setState(() {

View file

@ -2,7 +2,6 @@ import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../../globals.dart';
class CreateMatchPage extends StatefulWidget { class CreateMatchPage extends StatefulWidget {
@override @override
@ -13,8 +12,7 @@ class _CreateMatchPageState extends State<CreateMatchPage> {
String? _matchId; String? _matchId;
bool _isLoading = false; bool _isLoading = false;
final String _createMatchApiUrl = final String _createMatchApiUrl = 'http://api.dthpp.mercurio.moe/creatematch'; // Replace with your API endpoint
'$apiurl/creatematch'; // Replace with your API endpoint
// Method to create a match // Method to create a match
Future<void> _createMatch() async { Future<void> _createMatch() async {
@ -93,9 +91,9 @@ class _CreateMatchPageState extends State<CreateMatchPage> {
_isLoading _isLoading
? CircularProgressIndicator() // Show loading spinner ? CircularProgressIndicator() // Show loading spinner
: ElevatedButton( : ElevatedButton(
onPressed: _createMatch, onPressed: _createMatch,
child: Text('Create Match'), child: Text('Create Match'),
), ),
SizedBox(height: 16), SizedBox(height: 16),
if (_matchId != null) if (_matchId != null)
Text( Text(

View file

@ -2,7 +2,6 @@ import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../../globals.dart';
class AddFriendPage extends StatefulWidget { class AddFriendPage extends StatefulWidget {
@override @override
@ -14,8 +13,8 @@ class _AddFriendPageState extends State<AddFriendPage> {
List<dynamic> _friends = []; List<dynamic> _friends = [];
bool _isLoading = false; bool _isLoading = false;
final String _addFriendApiUrl = '$apiurl/add_friend'; final String _addFriendApiUrl = 'http://api.dthpp.mercurio.moe/add_friend';
final String _getFriendsApiUrl = '$apiurl/get_friends'; final String _getFriendsApiUrl = 'http://api.dthpp.mercurio.moe/get_friends';
// Method to add a friend // Method to add a friend
Future<void> _addFriend(String friendUid) async { Future<void> _addFriend(String friendUid) async {
@ -125,17 +124,17 @@ class _AddFriendPageState extends State<AddFriendPage> {
_isLoading _isLoading
? Center(child: CircularProgressIndicator()) ? Center(child: CircularProgressIndicator())
: Expanded( : Expanded(
child: ListView.builder( child: ListView.builder(
itemCount: _friends.length, itemCount: _friends.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final friend = _friends[index]; final friend = _friends[index];
return ListTile( return ListTile(
title: Text(friend['name']), title: Text(friend['name']),
subtitle: Text('UID: ${friend['uid']}'), subtitle: Text('UID: ${friend['uid']}'),
); );
}, },
), ),
), ),
], ],
), ),
), ),

View file

@ -2,7 +2,6 @@ import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../../globals.dart';
class JoinMatchPage extends StatefulWidget { class JoinMatchPage extends StatefulWidget {
@override @override
@ -17,9 +16,10 @@ class _JoinMatchPageState extends State<JoinMatchPage> {
int _player2Score = 0; int _player2Score = 0;
String? _matchId; String? _matchId;
final String _joinMatchApiUrl = '$apiurl/joinmatch'; final String _joinMatchApiUrl = 'http://api.dthpp.mercurio.moe/joinmatch'; // Replace with your API endpoint
final String _endMatchApiUrl = '$apiurl/endmatch'; final String _endMatchApiUrl = 'http://api.dthpp.mercurio.moe/endmatch'; // Replace with your API endpoint
// Join Match Function
Future<void> _joinMatch() async { Future<void> _joinMatch() async {
setState(() { setState(() {
_isLoading = true; _isLoading = true;
@ -64,6 +64,7 @@ class _JoinMatchPageState extends State<JoinMatchPage> {
} }
} }
// Increment/Decrement Player Scores
void _updateScore(int player, int delta) { void _updateScore(int player, int delta) {
setState(() { setState(() {
if (player == 1) { if (player == 1) {
@ -74,6 +75,7 @@ class _JoinMatchPageState extends State<JoinMatchPage> {
}); });
} }
// End Match Function
Future<void> _endMatch() async { Future<void> _endMatch() async {
setState(() { setState(() {
_isLoading = true; _isLoading = true;
@ -133,80 +135,80 @@ class _JoinMatchPageState extends State<JoinMatchPage> {
child: _isLoading child: _isLoading
? Center(child: CircularProgressIndicator()) ? Center(child: CircularProgressIndicator())
: _isJoined : _isJoined
? Column( ? Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
IconButton( IconButton(
icon: Icon(Icons.remove), icon: Icon(Icons.remove),
onPressed: () => _updateScore(1, -1), onPressed: () => _updateScore(1, -1),
), ),
Text( Text(
'Player 1 Score: $_player1Score', 'Player 1 Score: $_player1Score',
style: TextStyle(fontSize: 20), style: TextStyle(fontSize: 20),
), ),
IconButton( IconButton(
icon: Icon(Icons.add), icon: Icon(Icons.add),
onPressed: () => _updateScore(1, 1), onPressed: () => _updateScore(1, 1),
), ),
], ],
), ),
SizedBox(height: 16), SizedBox(height: 16),
// Player 2 Score Controls // Player 2 Score Controls
Row( Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
IconButton( IconButton(
icon: Icon(Icons.remove), icon: Icon(Icons.remove),
onPressed: () => _updateScore(2, -1), onPressed: () => _updateScore(2, -1),
), ),
Text( Text(
'Player 2 Score: $_player2Score', 'Player 2 Score: $_player2Score',
style: TextStyle(fontSize: 20), style: TextStyle(fontSize: 20),
), ),
IconButton( IconButton(
icon: Icon(Icons.add), icon: Icon(Icons.add),
onPressed: () => _updateScore(2, 1), onPressed: () => _updateScore(2, 1),
), ),
], ],
), ),
SizedBox(height: 32), SizedBox(height: 32),
// End Match Button // End Match Button
ElevatedButton( ElevatedButton(
onPressed: _endMatch, onPressed: _endMatch,
child: Text('End Match'), child: Text('End Match'),
), ),
], ],
) )
: Column( : Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
// Match ID Text Field // Match ID Text Field
TextField( TextField(
controller: _matchIdController, controller: _matchIdController,
decoration: InputDecoration( decoration: InputDecoration(
labelText: 'Enter Match ID', labelText: 'Enter Match ID',
border: OutlineInputBorder(), border: OutlineInputBorder(),
), ),
), ),
SizedBox(height: 16), SizedBox(height: 16),
// Join Match Button // Join Match Button
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
if (_matchIdController.text.isNotEmpty) { if (_matchIdController.text.isNotEmpty) {
_joinMatch(); _joinMatch();
} else { } else {
_showToast('Please enter a Match ID.'); _showToast('Please enter a Match ID.');
} }
}, },
child: Text('Join Match'), child: Text('Join Match'),
), ),
], ],
), ),
), ),
); );
} }

View file

@ -1,7 +1,6 @@
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import '../../globals.dart';
class LeaderboardPage extends StatefulWidget { class LeaderboardPage extends StatefulWidget {
@override @override
@ -12,7 +11,7 @@ class _LeaderboardPageState extends State<LeaderboardPage> {
List<dynamic> _leaderboard = []; List<dynamic> _leaderboard = [];
bool _isLoading = true; bool _isLoading = true;
final String _leaderboardApi = '$apiurl/leaderboards'; final String _apiUrl = 'http://api.dthpp.mercurio.moe/leaderboards';
Future<void> _fetchLeaderboard() async { Future<void> _fetchLeaderboard() async {
setState(() { setState(() {
@ -20,7 +19,7 @@ class _LeaderboardPageState extends State<LeaderboardPage> {
}); });
try { try {
final response = await http.get(Uri.parse(_leaderboardApi)); final response = await http.get(Uri.parse(_apiUrl));
if (response.statusCode == 200) { if (response.statusCode == 200) {
List<dynamic> data = json.decode(response.body); List<dynamic> data = json.decode(response.body);
@ -72,26 +71,26 @@ class _LeaderboardPageState extends State<LeaderboardPage> {
body: _isLoading body: _isLoading
? Center(child: CircularProgressIndicator()) ? Center(child: CircularProgressIndicator())
: RefreshIndicator( : RefreshIndicator(
onRefresh: _fetchLeaderboard, onRefresh: _fetchLeaderboard,
child: ListView.builder( child: ListView.builder(
itemCount: _leaderboard.length, itemCount: _leaderboard.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
var player = _leaderboard[index]; var player = _leaderboard[index];
return Card( return Card(
margin: EdgeInsets.all(8), margin: EdgeInsets.all(8),
child: ListTile( child: ListTile(
contentPadding: EdgeInsets.all(10), contentPadding: EdgeInsets.all(10),
leading: CircleAvatar( leading: CircleAvatar(
child: Text(player['player_name'][0].toUpperCase()), child: Text(player['player_name'][0].toUpperCase()),
), ),
title: Text(player['player_name']), title: Text(player['player_name']),
subtitle: Text('Elo Rating: ${player['elo_rating']}'), subtitle: Text('Elo Rating: ${player['elo_rating']}'),
trailing: Text('Friend Code: ${player['friend_code']}'), trailing: Text('Friend Code: ${player['friend_code']}'),
),
);
},
), ),
), );
},
),
),
); );
} }
} }

View file

@ -3,7 +3,6 @@ import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import '../../globals.dart';
class ProfilePage extends StatefulWidget { class ProfilePage extends StatefulWidget {
@override @override
@ -17,7 +16,7 @@ class _ProfilePageState extends State<ProfilePage> {
int? _elo; int? _elo;
List<dynamic> _matches = []; List<dynamic> _matches = [];
final String _getProfileApiUrl = '$apiurl/getprofile'; final String _getProfileApiUrl = 'http://api.dthpp.mercurio.moe/getprofile';
@override @override
void initState() { void initState() {
@ -80,116 +79,114 @@ class _ProfilePageState extends State<ProfilePage> {
body: _isLoading body: _isLoading
? Center(child: CircularProgressIndicator()) ? Center(child: CircularProgressIndicator())
: RefreshIndicator( : RefreshIndicator(
onRefresh: _fetchProfileData, onRefresh: _fetchProfileData,
child: Column( child: Column(
children: [
// Profile Details
Container(
padding: EdgeInsets.all(16.0),
child: Row(
children: [ children: [
// Profile Details // Profile Icon
Container( CircleAvatar(
padding: EdgeInsets.all(16.0), backgroundColor: _generateRandomColor(),
child: Row( child: Text(
children: [ _name != null && _name!.isNotEmpty
// Profile Icon ? _name![0].toUpperCase()
CircleAvatar( : '?',
backgroundColor: _generateRandomColor(), style: TextStyle(fontSize: 24, color: Colors.white),
child: Text(
_name != null && _name!.isNotEmpty
? _name![0].toUpperCase()
: '?',
style: TextStyle(fontSize: 24, color: Colors.white),
),
radius: 40,
),
SizedBox(width: 16),
// Profile Info
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_name ?? 'Name not available',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 8),
Text('UID: ${_uid ?? 'N/A'}'),
Text('ELO: ${_elo ?? 'N/A'}'),
],
),
],
), ),
radius: 40,
), ),
SizedBox(height: 16), SizedBox(width: 16),
// Recent Matches // Profile Info
Expanded( Column(
child: _matches.isEmpty crossAxisAlignment: CrossAxisAlignment.start,
? Center( children: [
child: Text( Text(
"You haven't played any matches yet", _name ?? 'Name not available',
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 24,
color: Colors.grey, fontWeight: FontWeight.bold,
), ),
), ),
) SizedBox(height: 8),
: ListView.builder( Text('UID: ${_uid ?? 'N/A'}'),
itemCount: _matches.length, Text('ELO: ${_elo ?? 'N/A'}'),
itemBuilder: (context, index) { ],
final match = _matches[index];
final result = match['result'];
final eloChange = match['elo_change'];
return Card(
margin: EdgeInsets.symmetric(
horizontal: 16.0, vertical: 8.0),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'Match ID: ${match['match_id']}',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
Text(
'Opponent: ${match['opponent_name']}'),
Row(
children: [
Text(
'$result',
style: TextStyle(
fontWeight: FontWeight.bold,
color: result == 'Win'
? Colors.green
: Colors.red,
),
),
SizedBox(width: 16),
if (eloChange != null)
Text(
'ELO Change: ${eloChange > 0 ? '+' : ''}$eloChange',
style: TextStyle(
color: eloChange > 0
? Colors.green
: Colors.red,
),
),
],
),
],
),
),
);
},
),
), ),
], ],
), ),
), ),
SizedBox(height: 16),
// Recent Matches
Expanded(
child: _matches.isEmpty
? Center(
child: Text(
"You haven't played any matches yet",
style: TextStyle(
fontSize: 16,
color: Colors.grey,
),
),
)
: ListView.builder(
itemCount: _matches.length,
itemBuilder: (context, index) {
final match = _matches[index];
final result = match['result'];
final eloChange = match['elo_change'];
return Card(
margin: EdgeInsets.symmetric(
horizontal: 16.0, vertical: 8.0),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Match ID: ${match['match_id']}',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
Text('Opponent: ${match['opponent_name']}'),
Row(
children: [
Text(
'$result',
style: TextStyle(
fontWeight: FontWeight.bold,
color: result == 'Win'
? Colors.green
: Colors.red,
),
),
SizedBox(width: 16),
if (eloChange != null)
Text(
'ELO Change: ${eloChange > 0 ? '+' : ''}$eloChange',
style: TextStyle(
color: eloChange > 0
? Colors.green
: Colors.red,
),
),
],
),
],
),
),
);
},
),
),
],
),
),
); );
} }
} }

View file

@ -1,8 +1,8 @@
name: pingpongapp name: pingpongapp
description: "DTH Ping Pong Score tracking app" description: "A new Flutter project."
publish_to: 'none' publish_to: 'none'
version: 0.0.34+1 version: 0.0.32+1
environment: environment:
sdk: '>=3.4.3 <4.0.0' sdk: '>=3.4.3 <4.0.0'