diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/globals.dart | 38 | ||||
-rw-r--r-- | lib/main.dart | 2 |
2 files changed, 15 insertions, 25 deletions
diff --git a/lib/globals.dart b/lib/globals.dart index 7195798..818183c 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -4,6 +4,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; +import 'package:http/http.dart' as http; //Variables bool isLoggedIn = false; @@ -15,7 +16,7 @@ String error = ""; String id = "0"; String firstname = ""; String email = ""; -String avatar ="https://api.adorable.io/avatars/128/BEAM-Messenger.png"; +String avatar = "https://api.adorable.io/avatars/128/BEAM-Messenger.png"; class Utility { static Future<Null> showAlertPopup( @@ -44,37 +45,26 @@ class Utility { ); } - static Future<String> getData(String params) async { + static Future<String> getData(Map params) async { var requestURL = apiURL; - requestURL = requestURL + params; -// requestURL = requestURL + "calltype=" + calltypeParm; -// requestURL = requestURL + "&mod=" + modParm; -// requestURL = requestURL + "&?action=" + actionParm; -// requestURL = requestURL + "&?param=" + paramsParm; -// requestURL = requestURL + "&?foo=" + fooParm; + requestURL = requestURL; print("Request URL: " + requestURL); var url = requestURL; - var httpClient = new HttpClient(); String result; + try { - var request = await httpClient.getUrl(Uri.parse(url)); - var response = await request.close(); - if (response.statusCode == HttpStatus.OK) { - try { - var json = await response.transform(UTF8.decoder).join(); - result = json; - } catch (exception) { - result = 'Error Getting Data'; - } - } else { - result = - 'Error getting IP address:\nHttp status ${response.statusCode}'; - } + await http.post(url, body: { + "email": params["email"], + "password": params["password"] + }).then((response) { + result = response.body; + print('Answer: ' + result.toString()); + }); } catch (exception) { - result = 'Failed getting IP address'; + result = 'Failed logging in'; } - print("Result: " + result); + return result; } diff --git a/lib/main.dart b/lib/main.dart index e547f62..e56c38d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -74,7 +74,7 @@ class LoginPageState extends State<LoginPage> { Future<bool> _loginRequest(String email, String password) async { String result = ""; - result = await globals.Utility.getData(""); + result = await globals.Utility.getData({'email': email, 'password': password}); //Decode Data try { |