diff --git a/lib/globals.dart b/lib/globals.dart index c5a70e6..4884e50 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -1,3 +1,3 @@ // lib/globals.dart const String apiurl = "https://api.dthpp.mercurio.moe"; -//const String apiurl = "http://10.0.0.10:9134"; +//const String apiurl = "http://192.168.1.120:9134"; diff --git a/lib/pages/home.dart b/lib/pages/home.dart index a91e98b..9acd44d 100644 --- a/lib/pages/home.dart +++ b/lib/pages/home.dart @@ -43,7 +43,7 @@ class _HomePageState extends State { } Future> fetchCommitHashes() async { - const apiUrl = '$apiurl/latest-commit-hashes'; + const apiUrl = '$apiurl/version'; try { final response = await http.get(Uri.parse(apiUrl)); diff --git a/lib/pages/login.dart b/lib/pages/login.dart index a2cf1fa..3a76ac5 100644 --- a/lib/pages/login.dart +++ b/lib/pages/login.dart @@ -4,6 +4,8 @@ import 'package:http/http.dart' as http; import 'dart:convert'; import 'home.dart'; import '../globals.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:url_launcher/url_launcher.dart'; class LoginPage extends StatefulWidget { @override @@ -21,6 +23,17 @@ class _LoginPageState extends State { Future _handleAuth() async { final email = _emailController.text.trim(); final password = _passwordController.text.trim(); + final displayName = _displayNameController.text.trim(); + + // Input validation + if (email.isEmpty || + password.isEmpty || + (!_isLogin && displayName.isEmpty)) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Please fill in all required fields.')), + ); + return; + } setState(() { _isLoading = true; @@ -36,8 +49,7 @@ class _LoginPageState extends State { context, MaterialPageRoute(builder: (context) => HomePage())); } } else { - final uid = await _register( - email, password, _displayNameController.text.trim()); + final uid = await _register(email, password, displayName); if (uid != null) { setState(() { _isLogin = true; @@ -118,21 +130,61 @@ class _LoginPageState extends State { decoration: InputDecoration(labelText: 'Display Name'), ), const SizedBox(height: 20), - _isLoading - ? CircularProgressIndicator() - : ElevatedButton( + if (_isLoading) + CircularProgressIndicator() + else + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + ElevatedButton( onPressed: _handleAuth, child: Text(_isLogin ? 'Login' : 'Register'), ), - TextButton( - onPressed: () { - setState(() { - _isLogin = !_isLogin; - }); - }, - child: Text(_isLogin - ? 'Don\'t have an account? Register' - : 'Already have an account? Login'), + ElevatedButton( + onPressed: () { + setState(() { + _isLogin = !_isLogin; + }); + }, + child: Text(_isLogin ? 'Register' : 'Back to Login'), + ), + ], + ), + const Spacer(), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + IconButton( + icon: Icon(FontAwesomeIcons.github), + onPressed: () async { + final url = Uri.parse( + 'https://git.mercurio.moe/Mercury/dth-pingpong-mobileapp'); + if (await canLaunchUrl(url)) { + await launchUrl( + url, + mode: LaunchMode + .externalApplication, // Ensures it opens in the browser + ); + } else { + throw 'Could not launch $url'; + } + }), + IconButton( + icon: Icon(FontAwesomeIcons.chartSimple), + onPressed: () async { + final url = + Uri.parse('https://kuma.mercurio.moe/status/dthpp'); + if (await canLaunchUrl(url)) { + await launchUrl( + url, + mode: LaunchMode + .externalApplication, // Ensures it opens in the browser + ); + } else { + throw 'Could not launch $url'; + } + }), + ], ), ], ), diff --git a/lib/pages/views/creatematch.dart b/lib/pages/views/creatematch.dart index a68a789..39e4a8f 100644 --- a/lib/pages/views/creatematch.dart +++ b/lib/pages/views/creatematch.dart @@ -13,10 +13,8 @@ class _CreateMatchPageState extends State { String? _matchId; bool _isLoading = false; - final String _createMatchApiUrl = - '$apiurl/creatematch'; // Replace with your API endpoint + final String _createMatchApiUrl = '$apiurl/creatematch'; - // Method to create a match Future _createMatch() async { setState(() { _isLoading = true; diff --git a/pubspec.yaml b/pubspec.yaml index 7657d1d..83f722c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,6 +15,8 @@ dependencies: http: ^1.2.2 logger: ^2.5.0 package_info: ^2.0.2 + font_awesome_flutter: ^10.8.0 + url_launcher: ^6.3.1 dev_dependencies: flutter_test: