objectbox-dart
objectbox-dart copied to clipboard
Admin error in multiple flutter engines
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.
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?
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.
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.
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.