build.gradle
file of your project (not the ones for your app or module) and add a global variable for the version and the ObjectBox Gradle plugin:build.gradle
file for your app or module and, after the com.android.application
plugin, apply the io.objectbox plugin
:pubspec.yaml
:flutter pub get
${ARCHS_STANDARD}
with arm64
(or $ARCHS_STANDARD_64_BIT
). macos/Runner/*.entitlements
files if they contain a <dict>
section with correct group ID info. Change the string value to the DEVELOPMENT_TEAM
you can find in your Xcode settings, plus an application-specific suffix, for example: openStore(macosApplicationGroup: 'FGDTDLOBXDJ.demo')
. Note: Pick a short group identifier; there's an internal limit in macOS that requires the complete string to be 19 characters or fewer.bash <(curl -s https://raw.githubusercontent.com/objectbox/objectbox-dart/main/install.sh)
pubspec.yaml
:dart pub get
lib
subdirectory of the working directory. It's not necessary to install the library system-wide. This also allows to use different versions for different projects. For details see below.--sync
argument to the script:install.sh
needs to be shipped with the executable.install.sh
script downloads the library by default to the lib
subdirectory of the working directory. An executable using ObjectBox Dart looks for the library in this lib
directory.DynamicLibrary.open
):%WINDIR%\system32
. /usr/local/lib
(and maybe others). /lib
and /usr/lib
(again, possibly others).@Entity
and @Id
. A simple entity representing a user could look like this:long
(or Long
in Kotlin, int
in Dart). If you need to use other types, like a String ID, see the @Id annotation docs. Also, it must have non-private visibility (or non-private getter and setter methods).flutter pub run build_runner build
to generate the binding code required to use ObjectBox.@Entity
annotations in your lib
folder and create a single database definition lib/objectbox-model.json
and supporting code in lib/objectbox.g.dart
objectbox.g.dart
to your version control ignore list (e.g. .gitignore
), otherwise build_runner will complain about it being changed each time you pull a change.dart run build_runner build
to generate the binding code required to use ObjectBox.@Entity
annotations in your lib
folder and create a single database definition lib/objectbox-model.json
and supporting code in lib/objectbox.g.dart
objectbox.g.dart
to your version control ignore list (e.g. .gitignore
), otherwise build_runner will complain about it being changed each time you pull a change.app/objectbox-models/default.json
for Android projects, or lib/objectbox-model.json
for Dart/Flutter projects. This JSON file changes when you change your entity classes (or sometimes with a new version of ObjectBox).default.json
model file.MyObjectBox
class, for example in a small helper class like this:UnsatisfiedLinkError
or LinkageError
on the build call, see App Bundle, split APKs and Multidex for solutions.onCreate
method of your Application class:UnsatisfiedLinkError
or LinkageError
on the build call, see App Bundle, split APKs and Multidex for solutions.onCreate
method of your Application class:openStore()
method, for example in a small helper class like this:openStore()
does, if you don't overwrite the default directory
argument.failed to create store: 10199 Dir does not exist: objectbox (30)
.main()
function:getObjectBoxModel()
method, for example like this:(directory: )
, using the default - ./objectbox
- in the current working directory.User
and Order
entities, you need a Box object to interact with each:put
also supports putting multiple objects, which is more efficient.get
reads it from its box. To get all objects in the box use getAll
.remove
also supports removing multiple objects, which is more efficient. removeAll
removes (deletes) all objects in a box.awaitAsyncCompletion()
and awaitAsyncSubmitted()
to wait for the async queue to finish.0
(zero) or null
(if using java.lang.Long) As said above, when putting an object with ID zero it will be assigned an unused ID (not zero).0xFFFFFFFFFFFFFFFF
(-1 in Java) Reserved for internal use.put
runs an implicit transaction.put
bulk overloads for lists (like put(entities)
) when possible.runInTx()
.