getObjectTree method

  1. @override
String getObjectTree(
  1. String id, {
  2. List<String> properties = const [],
})
override

Returns the SAP object tree in JSON format. id can be "wnd0" for a specific window, or empty "" for the entire session. properties is a list of properties you want to extract (e.g., "Id", "Text", "Type").

Implementation

@override
String getObjectTree(String id, {List<String> properties = const []}) {
  if (isInvalid) return "{}";
  final ptrId = id.toNativeUtf16();
  Pointer<Pointer<Utf16>> ptrProps = nullptr;
  try {
    if (properties.isNotEmpty) {
      ptrProps = calloc<Pointer<Utf16>>(properties.length);
      for (int i = 0; i < properties.length; i++) {
        ptrProps[i] = properties[i].toNativeUtf16();
      }
    }
    final resPtr = _api.getObjectTree(
      handle,
      ptrId,
      ptrProps,
      properties.length,
    );
    if (resPtr == nullptr) return "{}";
    final jsonStr = resPtr.toDartString();
    _api.freeString(resPtr);
    return jsonStr;
  } finally {
    malloc.free(ptrId);
    if (ptrProps != nullptr) {
      for (int i = 0; i < properties.length; i++) {
        malloc.free(ptrProps[i]);
      }
      calloc.free(ptrProps);
    }
  }
}