AddressCRUD method

Future AddressCRUD({
  1. dynamic posttype,
  2. dynamic addressid,
  3. dynamic type,
  4. dynamic address,
  5. dynamic towerplotnum,
  6. dynamic societyname,
  7. dynamic pincode,
  8. dynamic city,
  9. dynamic state,
  10. dynamic name,
  11. dynamic email,
  12. dynamic mobile,
  13. dynamic landmark,
  14. dynamic fromscreen,
  15. dynamic context,
})

Implementation

Future AddressCRUD(
    {posttype,
    addressid,
    type,
    address,
    towerplotnum,
    societyname,
    pincode,
    city,
    state,
    name,
    email,
    mobile,
    landmark,
    fromscreen,
    context}) async {
  var decodedResponse;
  final ApiBody = {
    'post_type': '${posttype}',
    'address_id': '${addressid}',
    'type': '${type}',
    'address': '${address}',
    'tower_plot_no': '${towerplotnum}',
    'society_name': '${societyname}',
    'pincode': '${pincode}',
    'city': '${city}',
    'state': '${state}',
    'name': '${name}',
    'email': '${email}',
    'mobile': '${mobile}',
    'landmark': '${landmark}'
  };
  try {
    final response = await http.post(
      Uri.parse('${SDK_BASE_URL}medicine_api/add_user_address'),
      headers: {'Authorization': SignUpController.currentUserToken},
      body: ApiBody,
    );
    decodedResponse = json.decode(response.body);
    if (decodedResponse['status'] == 200) {
      fromscreen == 'Med'
          ? Get.to(AddressDisplay(
              fromscreen: 'Med',
            ))
          : Get.to(AddressDisplay(fromscreen: 'Test'));
      Loading = 'end';
      showDialog(
        barrierDismissible: false,
        context: context,
        builder: (BuildContext context) {
          return PinCodePopUp(
            messag: "${decodedResponse['message']}",
            image: '${LottiePath}Upload_Successful.json',
          );
        },
      );
      if (posttype == 'delete') {
        (context as Element).reassemble();
      } else {
        null;
      }
    } else {
      Loading = 'end';
      showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context) {
          return PinCodePopUp(
            messag: "Something Went Wrong",
            image: '${LottiePath}Error.json',
          );
        },
      );
    }
  } catch (e) {
    errorListner(
        apiname: 'medicine_api/add_user_address',
        responsed: "${decodedResponse}",
        request: "",
        app_error: '${e}');
  }
}