diff --git a/app/lib/consts.dart b/app/lib/consts.dart new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/app/lib/main.dart b/app/lib/main.dart index d2d9e0c98242ce794729148d852ef1fb5a7f7774..042f7ec8633880503c08330ce3c706a50005d63c 100644 --- a/app/lib/main.dart +++ b/app/lib/main.dart @@ -6,28 +6,12 @@ import 'dart:io'; const String port = "8443"; const String serverURI = "https://127.0.0.1:$port/"; +const String mapEndpoint = "update_map"; +// NB: if http connection fails, run: adb reverse tcp:8443 tcp:8443 const int fetchInterval = 5; -Future<void> main() async { - // NB temporary test print - print(serverURI); - - try { - // Create a custom HTTP client with disabled SSL certificate validation - HttpClient client = HttpClient() - ..badCertificateCallback = - (X509Certificate cert, String host, int port) => true; - - // Use the custom HTTP client for requests - var request = await client.getUrl(Uri.parse(serverURI)); - var response = await request.close(); - - // Handle response - print('Response status: ${response.statusCode}'); - } catch (e) { - // Handle connection error - print('Failed to connect to the server: $e'); - } +void main() { + runApp(App()); } class App extends StatelessWidget { @@ -43,17 +27,20 @@ class App extends StatelessWidget { // fetchData requests data from the update_map endpoint Future<void> fetchData() async { - final response = await http.get(Uri.parse(serverURI)); + // NB: temp test print + print("fetchData triggered!"); + try { + // Custom HTTP client + HttpClient client = HttpClient() + ..badCertificateCallback = // NB: temporary disable SSL certificate validation + (X509Certificate cert, String host, int port) => true; - if (response.statusCode == 200) { - // Parse the JSON response - Map<String, dynamic> data = jsonDecode(response.body); - - // NB temporary test print - print(data); - print("Test print, fetchData triggered"); - } else { // Handle the error case - print('Failed to fetch data. Status code: ${response.statusCode}'); + var request = await client.getUrl(Uri.parse(serverURI+mapEndpoint)); + var response = await request.close(); + + print('Response status: ${response.statusCode}'); + } catch (e) { + print('Failed to connect to the server: $e'); } }