get method

String get(
  1. String? key
)

Gets an item of the StringDict object.

param key Unique key of the item to get. return item to get. throws DocumentException An error has occurred during Document Library execution.

Implementation

String get(String? key) {
  Pointer<Char>? pKey = key?.toNativeUtf8().cast<Char>();
  Pointer<Char> pItem = nullptr;
  Pointer<Int> pItemSize = calloc.allocate(1);
  pItemSize[0] = -1;
  try {
    var err = documentSDK.id3DocumentStringDict_Get(_pHandle.value, pKey ?? nullptr, pItem, pItemSize);
    if (err == DocumentError.insufficientBuffer.value) {
      pItem = calloc.allocate(pItemSize.value);
      err = documentSDK.id3DocumentStringDict_Get(_pHandle.value, pKey ?? nullptr, pItem, pItemSize);
      if (err != DocumentError.success.value) {
        throw DocumentException(err);
      }
    }
    final vItem = utf8.decode(Uint8List.fromList(pItem.cast<Uint8>().asTypedList(pItemSize.value)));
    return vItem;
  } finally {
    if (pKey != null) {
      calloc.free(pKey);
    }
    calloc.free(pItem);
    calloc.free(pItemSize);
  }
}