addAgent method

Future<bool> addAgent()

Implementation

Future<bool> addAgent() async {
  Map<String, String> data = {
    "email": agentEmailController.text,
    "firstName": agentFirstNameController.text,
    "lastName": agentLastNameController.text,
    "phone": agentPhoneController.text,
    "countryCode": agentCountryCode.value,
    "password": agentPasswordController.text,
  };
  print(data);
  var response = await Requests.getDio().post("dashboard/agents", data: data);
  if (response.statusCode == 200) {
    clearAgentFields();
    await getAgents();
    AdminDialog(
      image: 'assets/admins/success.png',
      title1: 'Agent Added Successfully',
      title2: 'The new Agent has been added successfully.',
      buttonText1: 'Go to Agent List',
      onTap1: () => Get.back(),
      buttonText2: 'Add New',
      onTap2: () {
        Get.back();
        AddNewAgentDialog().show();
      },
    ).show();
    // DefaultSnackbar.show("Success", "Agent Added Successfully");
    print(response.data);
    return true;
  } else {
    print(response.data);
    AdminDialog2(
      image: 'assets/admins/fail.png',
      title1: 'Failed to Add Agent',
      title2:
          'There was an issue adding the new agent. Please check the details and try again.',
      buttonText2: 'Try Again',
      onTap2: () {
        Get.back();
        AddNewAgentDialog().show();
      },
    ).show();
    DefaultSnackbar.show(
        "Error",
        response.data["message"] ??
            response.data?["errorCode"] ??
            response.data?["message"]?["errorCode"] ??
            "Something unexpected happened. Please try again later!",
        duration: Duration(milliseconds: 1300));
    return false;
  }
}