openCloudDBZone2 method Null safety

Future<AGConnectCloudDBZone> openCloudDBZone2(
  1. {required AGConnectCloudDBZoneConfig zoneConfig,
  2. bool isAllowToCreate = true}
)

You can invoke this API to create or open an object of a Cloud DB zone on the device. An object of a Cloud DB zone represents a unique data storage zone. An application supports a maximum of 4 Cloud DB zone on the device.

You can open a Cloud DB zone for multiple times, but need to close the Cloud DB zone after the operation is complete. That is, opening a Cloud DB zone must be followed by a closing operation. Otherwise, an exception is thrown during deletion.

When you use the Cloud DB zone config object to open an existing Cloud DB zone, ensure that the properties specified in Cloud DB zone config are the same as those of the existing Cloud DB zone. If they are different, the system throws an exception.

isAllowToCreate

  • true: If the Cloud DB zone exists in the CloudDBZoneConfig object, open the existing Cloud DB zone. If the Cloud DB zone does not exist in the Cloud DB zone config object, create an Cloud DB zone object.
  • false: Open an existing Cloud DB zone. If no Cloud DB zone exists, an exception is thrown.

Implementation

Future<AGConnectCloudDBZone> openCloudDBZone2({
  required AGConnectCloudDBZoneConfig zoneConfig,
  bool isAllowToCreate = true,
}) async {
  try {
    final Map<dynamic, dynamic>? result =
        await _methodChannel.invokeMethod<Map<dynamic, dynamic>?>(
      _MethodConstants.OPEN_CLOUD_DB_ZONE_2,
      <String, dynamic>{
        _KeyConstants.ZONE_CONFIG: zoneConfig._toMap(),
        _KeyConstants.IS_ALLOW_TO_CREATE: isAllowToCreate,
      },
    );
    return AGConnectCloudDBZone._(
        Map<String, dynamic>.from(result!)[_KeyConstants.ZONE_ID]);
  } catch (e) {
    throw AGConnectCloudDBException._from(e);
  }
}