request static method

Future<Result> request(
  1. String method,
  2. String uri, [
  3. String? body
])

Implementation

static Future<Result> request(String method, String uri,
    [String? body]) async {
  var url = Uri.parse(uri);
  Map<String, String> headers = {
    "x-authing-userpool-id": Authing.sUserPoolId,
    "x-authing-app-id": Authing.sAppId,
    "x-authing-request-from": "sdk-flutter",
    "x-authing-sdk-version": Authing.VERSION,
    "content-type": "application/json",
    "x-authing-lang": Util.getLangHeader()
  };
  if (currentUser != null) {
    if (currentUser!.mfaToken != null) {
      headers.putIfAbsent(
          "Authorization", () => "Bearer " + currentUser!.mfaToken!);
    } else {
      headers.putIfAbsent(
          "Authorization", () => "Bearer " + currentUser!.token);
    }
  } else {
    final prefs = await SharedPreferences.getInstance();
    final token = prefs.getString(keyToken);
    if (token != null) {
      headers.putIfAbsent("Authorization", () => "Bearer " + token);
    }
  }

  method = method.toLowerCase();
  http.Response? response;
  if (method == 'get') {
    response = await http.get(url, headers: headers);
  } else if (method == 'post') {
    response = await http.post(url, headers: headers, body: body);
  } else if (method == 'delete') {
    response = await http.delete(url, headers: headers, body: body);
  }
  return parseResponse(response);
}