I'm trying to store data locally with ObjectBox in Flutter, and I started getting this error. Everything looks good according to the documentation, I'm unsure why I'm getting errors from the objectbox.g.dart file: StateError (Bad state: failed to create store: Cannot open store: another store is still open using the same path: "/data/data/com.example.my_app/app_flutter/objectbox" (OBX_ERROR code 10001)).
// initializations
late ObjectBox objectBox;
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
objectBox = await ObjectBox.init();
runApp(const MyApp());
}
// main code
// object_box.dart
class ObjectBox {
late final Store _store;
late final Box<RoutineDB> _routineBox;
late final Box<ExerciseDB> _exerciseBox;
ObjectBox._init(this._store) {
_routineBox = Box<RoutineDB>(_store);
_exerciseBox = Box<ExerciseDB>(_store);
}
static Future<ObjectBox> init() async {
final dir = await getApplicationDocumentsDirectory();
final store = await openStore(directory: p.join(dir.path, "objectbox"));
return ObjectBox._init(store);
}
// other functions
}
The error appears in the "openStore" function within the objectbox.g.dart file.
Future<Store> openStore(
{String? directory,
int? maxDBSizeInKB,
int? fileMode,
int? maxReaders,
bool queriesCaseSensitiveDefault = true,
String? macosApplicationGroup}) async =>
Store(getObjectBoxModel(), // getting error here
directory: directory ?? (await defaultStoreDirectory()).path,
maxDBSizeInKB: maxDBSizeInKB,
fileMode: fileMode,
maxReaders: maxReaders,
queriesCaseSensitiveDefault: queriesCaseSensitiveDefault,
macosApplicationGroup: macosApplicationGroup);