askarSessionFetchAll function

Future<AskarResult<EntryListHandle>> askarSessionFetchAll(
  1. SessionHandle handle,
  2. String category, {
  3. required bool forUpdate,
  4. Map? tagFilter,
  5. int? limit,
})

Implementation

Future<AskarResult<EntryListHandle>> askarSessionFetchAll(
  SessionHandle handle,
  String category, {
  required bool forUpdate,
  Map? tagFilter,
  int? limit,
}) async {
  Pointer<Utf8> categoryPtr = nullptr;
  Pointer<Utf8> tagFilterPtr = nullptr;

  try {
    categoryPtr = category.toNativeUtf8();
    tagFilterPtr = jsonEncode(tagFilter).toNativeUtf8();

    final callback = newCallbackWithHandle();

    final result = nativeAskarSessionFetchAll(
      handle.toInt(),
      categoryPtr,
      tagFilterPtr,
      (limit ?? 0),
      boolToInt(forUpdate),
      callback.nativeCallable.nativeFunction,
      callback.id,
    );

    final callbackResult = await callback.handleResult(result);

    return AskarResult<EntryListHandle>(
      callbackResult.errorCode,
      EntryListHandle(callbackResult.value),
    );
  } finally {
    freePointer(categoryPtr);
    freePointer(tagFilterPtr);
  }
}