slideButton method
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 ofCyberCieraModel
containing API-related details.
Function Workflow:
- Resets
isVerified
andisOtherLoading
state. - Clears previous error messages.
- Constructs a request payload with device information, request ID, and visitor ID.
- Sends an HTTP POST request via
ApiManager.post()
. - If API response is
"success"
, it validates the token:- If validation succeeds, sets
isVerified
totrue
. - If validation fails, logs an error and keeps
isVerified
asfalse
.
- If validation succeeds, sets
- If API response is
"fail"
, setsisVerified
tofalse
. - Handles API errors and unexpected exceptions, displaying appropriate error messages.
- Resets
isOtherLoading
tofalse
in thefinally
block.
Implementation
slideButton(context, CyberSiaraModel 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);
}
}