Admin constructor

Admin(
  1. Store store, {
  2. String bindUri = 'http://127.0.0.1:8090',
})

Creates an ObjectBox Admin associated with the given store and options.

Implementation

Admin(Store store, {String bindUri = 'http://127.0.0.1:8090'}) {
  if (!isAvailable()) {
    throw UnsupportedError(
        'Admin is not available in the loaded ObjectBox runtime library.');
  }
  initializeDartAPI();

  final opt = checkObxPtr(C.admin_opt());
  try {
    checkObx(C.admin_opt_store(opt, InternalStoreAccess.ptr(store)));
    checkObx(C.admin_opt_user_management(opt, false));
    withNativeString(bindUri,
        (Pointer<Int8> cStr) => checkObx(C.admin_opt_bind(opt, cStr)));
  } catch (_) {
    C.admin_opt_free(opt);
    rethrow;
  }

  _cAdmin = C.admin(opt);

  // Keep the finalizer so we can detach it when close() is called manually.
  _cFinalizer = C.dartc_attach_finalizer(
      this, native_admin_close, _cAdmin.cast(), 1024 * 1024);
  if (_cFinalizer == nullptr) {
    close();
    throwLatestNativeError();
  }
}