getMyDeviceInfo method

dynamic getMyDeviceInfo(
  1. double height,
  2. double width,
  3. CyberSiaraModel cieraModel
)

Fetches and sends device information to the CyberCiera API.

This function retrieves the device's IP address, unique device ID (UDID), and other relevant details such as device type, browser identity, and dimensions. The collected data is then sent to an API endpoint (getCyberSiaraForAndroid). If the API response is successful, it updates requestId and visiterId, otherwise, it logs an error message.

Parameters:

  • height: The height of the device screen.
  • width: The width of the device screen.
  • cieraModel: An instance of CyberCieraModel containing API-related information.

This function:

  • Resets loading state and error messages before making an API call.
  • Retrieves the device's IP address and UDID.
  • Determines the device type (Android or iOS) and extracts the device name.
  • Constructs a request payload containing device details.
  • Sends the request using ApiManager.post().
  • Parses the response and updates requestId and visiterId on success.
  • Displays an error message if the API request fails.

Implementation

getMyDeviceInfo(double height, double width, CyberSiaraModel cieraModel) async {
  isLoading(true);
  error("");
  apiError("");
  requestId("");
  visiterId("");
  removeToken();
  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(),
    };

    ResponseAPI responseAPI = await ApiManager.post(methodName: ApiConstant.getCyberSiaraForAndroid, params: map);
    Map<String, dynamic> valueMap = (responseAPI.response);
    if (valueMap["Message"] == "success") {
      GetInfoModel getInfoModel = GetInfoModel.fromJson(valueMap);
      requestId.value = getInfoModel.requestId;
      visiterId.value = getInfoModel.visiterId;
    } else {
      apiError(valueMap["Message"]);
      toast(apiError.value.toString());
    }
  } catch (err) {
    error(err.toString());
    toast(err.toString());
  } finally {
    isLoading(false);
  }
}