getCaptcha method
dynamic
getCaptcha({
- required double height,
- required double width,
- required String visiterId,
- required CyberCieraModel cieraModel,
Fetches a CAPTCHA challenge for user verification.
This function sends a POST
request to the captchaForAndroid
endpoint
with device and user session details. It retrieves a CAPTCHA URL in HTML format
if the request is successful.
Parameters:
height
: The device screen height (used for UI adjustments).width
: The device screen width (used for UI adjustments).visiterId
: A unique identifier for the user session.cieraModel
: An instance ofCyberCieraModel
containing API-related configurations.
Function Workflow:
- Sets
isOtherLoading
totrue
to indicate a loading state. - Clears previous error messages and CAPTCHA URLs.
- Fetches the device's IP and unique ID (
udid
). - Detects the device type (
Android
oriOS
) and extracts the device name. - Constructs a request payload containing:
- Master URL ID
- Request URL
- Browser Identity (
udid
) - Device IP and details
- Screen dimensions
- User session (
VisiterId
)
- Sends the request using
ApiManager.post()
. - Parses the response:
- If successful (
Message == "success"
), updatescaptchaUrl
with the received HTML. - Otherwise, displays an API error message.
- If successful (
- Catches and logs any errors encountered.
- Finally, sets
isOtherLoading
tofalse
to stop the loading state.
Returns:
- Updates the
captchaUrl
observable with the CAPTCHA HTML. - Displays an error toast in case of failure.
Implementation
getCaptcha({required double height, required double width, required String visiterId, required CyberCieraModel cieraModel}) async {
isOtherLoading(true);
error("");
captchaUrl("");
try {
deviceName = "";
deviceIp = await _ipAddress.getIp();
udid = await FlutterUdid.udid;
if (Platform.isAndroid) {
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
deviceName = androidInfo.brand;
} else {
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
deviceName = iosInfo.model;
}
Map<String, dynamic> map = {
"MasterUrlId": cieraModel.masterUrlId, // "VYz433DfqQ5LhBcgaamnbw4Wy4K9CyQT",
"RequestUrl": cieraModel.requestUrl, // "com.app.cyber_ceiara",
"BrowserIdentity": udid,
"DeviceIp": deviceIp,
"DeviceType": Platform.isAndroid ? "Android" : "ios",
"DeviceBrowser": 'Chrome',
"DeviceName": deviceName,
"DeviceHeight": height.round(),
"DeviceWidth": width.round(),
"VisiterId": visiterId,
};
ResponseAPI responseAPI = await ApiManager.post(methodName: ApiConstant.captchaForAndroid, params: map);
Map<String, dynamic> valueMap = responseAPI.response;
if (valueMap["Message"] == "success") {
captchaUrl(valueMap["HtmlFormate"]);
} else {
toast("Api Error");
}
} catch (err) {
error(err.toString());
toast(error.value);
} finally {
isOtherLoading(false);
}
}