slideButton method

dynamic slideButton(
  1. dynamic context,
  2. CyberCieraModel cieraModel
)

Sends device verification data to the CyberCiera API.

This function constructs a request payload with device-related information and sends it to the API endpoint (verifiedSubmitForAndroid) for verification. If the response is successful, it attempts to validate the received token. If validation succeeds, the isVerified flag is set to true; otherwise, it remains false.

Parameters:

  • context: The current BuildContext (not used in this function but may be useful for UI-related actions).
  • cieraModel: An instance of CyberCieraModel containing API-related details.

Function Workflow:

  1. Resets isVerified and isOtherLoading state.
  2. Clears previous error messages.
  3. Constructs a request payload with device information, request ID, and visitor ID.
  4. Sends an HTTP POST request via ApiManager.post().
  5. If API response is "success", it validates the token:
    • If validation succeeds, sets isVerified to true.
    • If validation fails, logs an error and keeps isVerified as false.
  6. If API response is "fail", sets isVerified to false.
  7. Handles API errors and unexpected exceptions, displaying appropriate error messages.
  8. Resets isOtherLoading to false in the finally block.

Implementation

slideButton(context, CyberCieraModel cieraModel) async {
  isVerified(false);
  isOtherLoading(true);
  error("");
  apiError("");
  Map<String, dynamic> map = {
    "MasterUrl": cieraModel.masterUrlId,
    "BrowserIdentity": udid,
    "DeviceIp": deviceIp,
    "DeviceName": deviceName,
    // "DeviceType": Platform.isAndroid ? "Android" : "ios",
    // "DeviceBrowser": 'Chrome',
    "Protocol": "http",
    "second": "5",
    "RequestID": requestId.value,
    "VisiterId": visiterId.value
  };
  try {
    ResponseAPI responseAPI = await ApiManager.post(methodName: ApiConstant.verifiedSubmitForAndroid, params: map);
    Map<String, dynamic> valueMap = responseAPI.response;
    if (valueMap["Message"] == "success") {
      bool success = await validateToken(valueMap["data"], cieraModel);
      if (success) {
        isVerified(true);
      } else {
        error("We cannot verify your key.");
        isVerified(false);
      }
    } else if (valueMap["Message"] == "fail") {
      isVerified(false);
    } else {
      apiError(valueMap["Message"]);
      toast(apiError.value.toString());
    }
  } catch (err) {
    apiError(err.toString());
  } finally {
    isOtherLoading(false);
  }
}