AddAdress method

Future AddAdress({
  1. dynamic addresstype,
  2. dynamic name,
  3. dynamic mobile,
  4. dynamic email,
  5. dynamic address,
  6. dynamic landmark,
  7. dynamic city,
  8. dynamic state,
  9. dynamic pincode,
  10. dynamic addressAction,
  11. dynamic context,
})

Implementation

Future AddAdress(
    {addresstype,
    name,
    mobile,
    email,
    address,
    landmark,
    city,
    state,
    pincode,
    addressAction,
    context}) async {
  var decodedResponse;
  final ApiBody = {
    "address_id": addressAction,
    "name": "${name}",
    "mobile_no": "${mobile}",
    "email_id": "${email}",
    "type": "${addresstype}",
    "address": "${address}",
    "landmark": "${landmark}",
    "pincode": pincode,
    "city": "${city}",
    "state": "${state}"
  };
  try {
    Map data = ApiBody;
    var body = jsonEncode(data);

    final response = await http.post(
      Uri.parse('${medicine_API}api/diagnostic/store-user-address'),
      headers: {
        'Authorization': currentUserToken,
        "Content-Type": "application/json",
      },
      body: body,
    );
    decodedResponse = json.decode(response.body);
    Get.back();
    if (decodedResponse['success'] == true) {
      await getAddressList();
      Get.off(AddressList());
      Validator().successMessage(
          context: context, message: "${decodedResponse['message']}");
    }
  } catch (e) {
    ErrorListner(
        apiname: 'api/diagnostic/store-user-address',
        responsed: "${decodedResponse}",
        request: "${ApiBody}",
        app_error: '${e}');
  }
}