objectbox-dart icon indicating copy to clipboard operation
objectbox-dart copied to clipboard

Admin error in multiple flutter engines

Open joo6077 opened this issue 3 years ago • 2 comments

Basic info (please complete the following information):

  • ObjectBox version: [1.6.0]
  • Flutter/Dart SDK: [3.0.5/2.14.4]
  • Null-safety enabled: [yes]
  • Reproducibility: [always]
  • OS: [mac M1]
  • Device/Emulator: [Galaxy S9]

Steps to reproduce

I'm using objectbox and audio_service in my project. I recently fixed objectbox duplicate store issue to check whether the store is opened or not. I used admin perfectly well before but after fixed those issues I got an error when I tried to use the admin.

Expected behavior

Admin work fine

Logs, stack traces

ArgumentError (Invalid argument(s): 10002 Argument "native_object" must not be null (L394))

Additional context

  • Is there anything special about your app? I'm using plugins objectbox and audio_service together.

joo6077 avatar Aug 09 '22 02:08 joo6077

Thanks for reporting! However, I can only speculate about the issue without a stack trace or info on how to reproduce this. Admin needs a Store instance to be supplied. This sounds like the Store instance it's given isn't valid?

greenrobot-team avatar Aug 09 '22 05:08 greenrobot-team

Oh I'm sorry, here is my code :

late Store store;
late Admin admin;

Future<void> initControllers() async {
  await _initialize();
  final appBox = store.box<AppModel>();

if (kDebugMode && Platform.isAndroid) {
    if (Admin.isAvailable()) {
       admin = Admin(store);
    }
  }
}

Future<String> _getDatabaseDirectoryPath() async {
  final dir = await getApplicationDocumentsDirectory();
  return '${dir.path}${Platform.pathSeparator}objectbox';
}

Future<void> _initialize() async {
  final dbPath = await _getDatabaseDirectoryPath();

  try {
    store = await openStore(directory: dbPath);
  } catch (error) {
    if (Store.isOpen(dbPath)) {
      store = Store.attach(getObjectBoxModel(), dbPath);
    }
  }
}

I initiate the Store first and then call Admin with the store.

joo6077 avatar Aug 09 '22 05:08 joo6077

Thanks! My guess is that using Admin with an attached store is not working.

E.g. if your code runs into the

  } catch (error) {
    if (Store.isOpen(dbPath)) {
      store = Store.attach(getObjectBoxModel(), dbPath);
    }
  }

case.

Check the stack trace, e.g. using logcat on Android to see which line exactly is the issue.

greenrobot-team avatar Aug 16 '22 12:08 greenrobot-team

Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue.

github-actions[bot] avatar Sep 07 '22 02:09 github-actions[bot]