apiSignUp function
Implementation
Future<int> apiSignUp(String username, password, email) async {
var pemBytes = await rootBundle.load("assets/cert.pem");
var context = SecurityContext()
..setTrustedCertificatesBytes(pemBytes.buffer.asUint8List(), password: '');
var client = HttpClient(context: context)
..badCertificateCallback =
(X509Certificate cert, String host, int port) => true;
try {
var request = await client
.postUrl(Uri.parse('https://api.gracehopper.xyz/v1/auth/sign-up'));
// Set headers
request.headers.add('Content-Type', 'application/json');
// Create JSON body
var body = jsonEncode(
{'username': username, 'password': password, 'email': email});
// Set body
request.write(body);
await request.close(); //comentar esta o las de abajo
var response = await request.close();
var responseBody = await response.transform(utf8.decoder).join();
// print(responseBody);
var responseBodyDictionary = jsonDecode(responseBody);
return responseBodyDictionary["status"]["error_code"];
} catch (e) {
// print(e);
return -1;
} finally {
client.close();
}
}