Add global page for api url
This commit is contained in:
parent
b7d48043df
commit
b6f8a4b320
3
lib/globals.dart
Normal file
3
lib/globals.dart
Normal file
|
@ -0,0 +1,3 @@
|
|||
// lib/globals.dart
|
||||
//const String apiurl = "https://api.dthpp.mercurio.moe";
|
||||
const String apiurl = "http://10.0.0.10:9134";
|
|
@ -17,7 +17,7 @@ class MyApp extends StatelessWidget {
|
|||
title: 'Ping Pong Tracker',
|
||||
theme: ThemeData.dark(useMaterial3: true).copyWith(
|
||||
colorScheme: ColorScheme.dark(
|
||||
primary: Colors.blue.shade900,
|
||||
primary: Colors.blue.shade800,
|
||||
),
|
||||
),
|
||||
home: EntryPoint(),
|
||||
|
|
|
@ -3,7 +3,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
import 'home.dart';
|
||||
|
||||
import '../globals.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
@override
|
||||
|
@ -18,8 +18,6 @@ class _LoginPageState extends State<LoginPage> {
|
|||
bool _isLogin = true;
|
||||
bool _isLoading = false;
|
||||
|
||||
final String baseUrl = 'http://api.dthpp.mercurio.moe';
|
||||
|
||||
Future<void> _handleAuth() async {
|
||||
final email = _emailController.text.trim();
|
||||
final password = _passwordController.text.trim();
|
||||
|
@ -38,13 +36,14 @@ class _LoginPageState extends State<LoginPage> {
|
|||
context, MaterialPageRoute(builder: (context) => HomePage()));
|
||||
}
|
||||
} else {
|
||||
final uid = await _register(email, password, _displayNameController.text.trim());
|
||||
final uid = await _register(
|
||||
email, password, _displayNameController.text.trim());
|
||||
if (uid != null) {
|
||||
setState(() {
|
||||
_isLogin = true;
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Registration successful! Please login.')));
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text('Registration successful! Please login.')));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
@ -58,7 +57,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||
}
|
||||
|
||||
Future<String?> _login(String email, String password) async {
|
||||
final url = Uri.parse('$baseUrl/login');
|
||||
final url = Uri.parse('$apiurl/login');
|
||||
final response = await http.post(
|
||||
url,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
|
@ -73,8 +72,9 @@ class _LoginPageState extends State<LoginPage> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<String?> _register(String email, String password, String displayName) async {
|
||||
final url = Uri.parse('$baseUrl/register');
|
||||
Future<String?> _register(
|
||||
String email, String password, String displayName) async {
|
||||
final url = Uri.parse('$apiurl/register');
|
||||
final response = await http.post(
|
||||
url,
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:convert';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../globals.dart';
|
||||
|
||||
class CreateMatchPage extends StatefulWidget {
|
||||
@override
|
||||
|
@ -12,7 +13,8 @@ class _CreateMatchPageState extends State<CreateMatchPage> {
|
|||
String? _matchId;
|
||||
bool _isLoading = false;
|
||||
|
||||
final String _createMatchApiUrl = 'http://api.dthpp.mercurio.moe/creatematch'; // Replace with your API endpoint
|
||||
final String _createMatchApiUrl =
|
||||
'$apiurl/creatematch'; // Replace with your API endpoint
|
||||
|
||||
// Method to create a match
|
||||
Future<void> _createMatch() async {
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:convert';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../globals.dart';
|
||||
|
||||
class AddFriendPage extends StatefulWidget {
|
||||
@override
|
||||
|
@ -13,8 +14,8 @@ class _AddFriendPageState extends State<AddFriendPage> {
|
|||
List<dynamic> _friends = [];
|
||||
bool _isLoading = false;
|
||||
|
||||
final String _addFriendApiUrl = 'http://api.dthpp.mercurio.moe/add_friend';
|
||||
final String _getFriendsApiUrl = 'http://api.dthpp.mercurio.moe/get_friends';
|
||||
final String _addFriendApiUrl = '$apiurl/add_friend';
|
||||
final String _getFriendsApiUrl = '$apiurl/get_friends';
|
||||
|
||||
// Method to add a friend
|
||||
Future<void> _addFriend(String friendUid) async {
|
||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:convert';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../globals.dart';
|
||||
|
||||
class JoinMatchPage extends StatefulWidget {
|
||||
@override
|
||||
|
@ -16,10 +17,9 @@ class _JoinMatchPageState extends State<JoinMatchPage> {
|
|||
int _player2Score = 0;
|
||||
String? _matchId;
|
||||
|
||||
final String _joinMatchApiUrl = 'http://api.dthpp.mercurio.moe/joinmatch'; // Replace with your API endpoint
|
||||
final String _endMatchApiUrl = 'http://api.dthpp.mercurio.moe/endmatch'; // Replace with your API endpoint
|
||||
final String _joinMatchApiUrl = '$apiurl/joinmatch';
|
||||
final String _endMatchApiUrl = '$apiurl/endmatch';
|
||||
|
||||
// Join Match Function
|
||||
Future<void> _joinMatch() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
|
@ -64,7 +64,6 @@ class _JoinMatchPageState extends State<JoinMatchPage> {
|
|||
}
|
||||
}
|
||||
|
||||
// Increment/Decrement Player Scores
|
||||
void _updateScore(int player, int delta) {
|
||||
setState(() {
|
||||
if (player == 1) {
|
||||
|
@ -75,7 +74,6 @@ class _JoinMatchPageState extends State<JoinMatchPage> {
|
|||
});
|
||||
}
|
||||
|
||||
// End Match Function
|
||||
Future<void> _endMatch() async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../../globals.dart';
|
||||
|
||||
class LeaderboardPage extends StatefulWidget {
|
||||
@override
|
||||
|
@ -11,7 +12,7 @@ class _LeaderboardPageState extends State<LeaderboardPage> {
|
|||
List<dynamic> _leaderboard = [];
|
||||
bool _isLoading = true;
|
||||
|
||||
final String _apiUrl = 'http://api.dthpp.mercurio.moe/leaderboards';
|
||||
final String _leaderboardApi = '$apiurl/leaderboards';
|
||||
|
||||
Future<void> _fetchLeaderboard() async {
|
||||
setState(() {
|
||||
|
@ -19,7 +20,7 @@ class _LeaderboardPageState extends State<LeaderboardPage> {
|
|||
});
|
||||
|
||||
try {
|
||||
final response = await http.get(Uri.parse(_apiUrl));
|
||||
final response = await http.get(Uri.parse(_leaderboardApi));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
List<dynamic> data = json.decode(response.body);
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:math';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../globals.dart';
|
||||
|
||||
class ProfilePage extends StatefulWidget {
|
||||
@override
|
||||
|
@ -16,7 +17,7 @@ class _ProfilePageState extends State<ProfilePage> {
|
|||
int? _elo;
|
||||
List<dynamic> _matches = [];
|
||||
|
||||
final String _getProfileApiUrl = 'http://api.dthpp.mercurio.moe/getprofile';
|
||||
final String _getProfileApiUrl = '$apiurl/getprofile';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -144,7 +145,8 @@ class _ProfilePageState extends State<ProfilePage> {
|
|||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Match ID: ${match['match_id']}',
|
||||
|
@ -153,7 +155,8 @@ class _ProfilePageState extends State<ProfilePage> {
|
|||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
Text('Opponent: ${match['opponent_name']}'),
|
||||
Text(
|
||||
'Opponent: ${match['opponent_name']}'),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
name: pingpongapp
|
||||
description: "A new Flutter project."
|
||||
description: "DTH Ping Pong Score tracking app"
|
||||
publish_to: 'none'
|
||||
|
||||
version: 0.0.32+1
|
||||
version: 0.0.34+1
|
||||
|
||||
environment:
|
||||
sdk: '>=3.4.3 <4.0.0'
|
||||
|
|
Loading…
Reference in a new issue