removeLocation static method

Future<Map<String, String>> removeLocation(
  1. int locationId
)

Implementation

static Future<Map<String, String>> removeLocation(int locationId) async {
  bool isTokenValid = await AuthService.validateToken();

  if (isTokenValid) {
    final res = await httpClient.delete(Config.getURI('/locations/$locationId.json'));

    debugPrint('[DEBUG]: statusCode ${res.statusCode}');
    debugPrint('[DEBUG]: Body ${res.body}');

    String error = 'Generic Error. Please try again.';
    if (res.body.isNotEmpty) {
      dynamic message = json.decode(res.body);
      error = message['error'] ? message['error'].toString().replaceAll('{', '').replaceAll('}', '') : '';
    }

    if (res.statusCode >= 400) return {'status': 'failed', 'message': error};

    return {'status': 'success', 'message': 'Location removed'};
  }
  return {'status': 'failed', 'message': 'An error occured. Please login again.'};
}