rescheduleAppointment method

Future<String?> rescheduleAppointment(
  1. String dateTime
)

Implementation

Future<String?> rescheduleAppointment(String dateTime) async {
  ///date format [dateTime] is 2021-04-22 06:00:00
  dynamic returnable;

  await SharedPreferences.getInstance().then((pref) async {
    String? token = pref.getString("token");

    Map data = {"dateTime": dateTime};
    prefs = await SharedPreferences.getInstance();
    String? client_id = iAmA == "consultant"
        ? Params.consultant_client_id
        : Params.patient_client_id;

    /*Calling the API url */
    var jsonData;
    final response = await http.post(
        Uri.parse(Params.base_url + "/appointments/2/reschedule/"),
        body: data,
        headers: {"Client-ID": "$client_id", "Authorization": "$token"});

    if (debug) {
      print('Status Code = ' +
          response.statusCode.toString() +
          ". Response: " +
          response.body);
    }

    /*If the response is 200 or 201 (success) then the response will be decoded */
    if (response.statusCode == 200 || response.statusCode == 201) {
      jsonData = json.decode(response.body);
      prefs.setString('dateTime', Tools().dateUtil(jsonData["dateTime"]));

      returnable = jsonData['message'];
    }
    // if dateTime in the past
    else if (response.statusCode == 400) {
      String message = jsonData['dateTime'].toString();
      returnable = message;
    } else {
      if (debug) print("Error Requesting API");
      print("error code");
      returnable = null;
    }
  });
  return returnable;
}