handleResultStringPointer function

String handleResultStringPointer(
  1. Pointer<Utf8> resultPtr
)

Returns a copy of the string returned by the native function and frees the given pointer. If the result contains an error, an Exception is raised.

Implementation

String handleResultStringPointer(Pointer<Utf8> resultPtr) {
  final resultStr = Utf8.fromUtf8(resultPtr);

  if (resultStr.startsWith("ERROR: ")) {
    final errMessage = "" + resultStr.substring(7);
    // Free the string pointer
    freeCString(resultPtr);
    throw Exception(errMessage);
  }

  final result = "" + resultStr;
  // Free the string pointer
  freeCString(resultPtr);
  return result;
}