sendRequest method

Future<Map<String, dynamic>> sendRequest({
  1. required String token,
  2. required String endpoint,
  3. required Object body,
})

Implementation

Future<Map<String, dynamic>> sendRequest({required String token, required String endpoint, required Object body}) async {
  try {
    var uri = Uri.parse(_URL_GRAPH + endpoint);
    var response = await http.post(uri, headers: {
      'Authorization': 'Bearer $token'
    }, body: body);
    var data = json.decode(response.body);
    if (data == null || data['error'] != null || response.statusCode != 200 || _isStatusCodeSuccess(data)) {
      print(data);
      return Future.value({});
    }
    return Future.value(data);
  } catch (exception) {
    return Future.error(exception);
  }
}