Box<T> class

A Box instance gives you access to objects of a particular type. You get Box instances via Store.box() or Box(Store).

For example, if you have User and Order entities, you need two Box objects to interact with them:

Box<User> userBox = store.box();
Box<Order> orderBox = store.box();

Constructors

Box(Store store)
Create a box for an Entity.
factory

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

contains(int id) → bool
Returns true if this box contains an Object with the ID id.
containsMany(List<int> ids) → bool
Returns true if this box contains objects with all of the given ids.
count({int limit = 0}) → int
Returns the count of all stored Objects in this box. If limit is not zero, stops counting at the given limit.
get(int id) → T?
Retrieves the stored object with the ID id from this box's database. Returns null if an object with the given ID doesn't exist.
getAll() → List<T>
Returns all stored objects in this Box.
getAllAsync() → Future<List<T>>
Like getAll, but runs the box operation asynchronously in a worker isolate.
getAsync(int id) → Future<T?>
Like get, but runs the box operation asynchronously in a worker isolate.
getMany(List<int> ids, {bool growableResult = false}) → List<T?>
Returns a list of Objects of type T, each located at the corresponding position of its ID in ids.
getManyAsync(List<int> ids, {bool growableResult = false}) → Future<List<T?>>
Like getMany, but runs the box operation asynchronously in a worker isolate.
isEmpty() → bool
Returns true if no objects are in this box.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
put(T object, {PutMode mode = PutMode.put}) → int
Puts the given object and returns its (new) ID.
putAndGetAsync(T object, {PutMode mode = PutMode.put}) → Future<T>
Like putAsync, but returns a copy of the object with the (new) ID set.
putAndGetManyAsync(List<T> objects, {PutMode mode = PutMode.put}) → Future<List<T>>
Like putManyAsync, but returns a copy of the objects with new IDs assigned.
putAsync(T object, {PutMode mode = PutMode.put}) → Future<int>
Like put, but runs in a worker isolate and does not modify the given object, e.g. to set a new ID.
putMany(List<T> objects, {PutMode mode = PutMode.put}) → List<int>
Like put, but optimized to put many objects at once.
putManyAsync(List<T> objects, {PutMode mode = PutMode.put}) → Future<List<int>>
Like putMany, but runs in a worker isolate and does not modify the given objects, e.g. to set an assigned ID.
putQueued(T object, {PutMode mode = PutMode.put}) → int
Schedules the given object to be put later on, by an asynchronous queue.
putQueuedAwaitResult(T object, {PutMode mode = PutMode.put}) → Future<int>
Like putQueued, but waits on the put to complete.
query([Condition<T>? qc]) → QueryBuilder<T>
Starts building a query which returns objects matching the supplied conditions.
remove(int id) → bool
Removes (deletes) the object with the given id.
removeAll() → int
Removes (deletes) all objects in this box. Returns the number of removed objects.
removeAllAsync() → Future<int>
Like removeAll, but runs in a worker isolate.
removeAsync(int id) → Future<bool>
Like remove, but runs in a worker isolate.
removeMany(List<int> ids) → int
Removes (deletes) objects with the given ids if they exist. Returns the number of removed objects.
removeManyAsync(List<int> ids) → Future<int>
Like removeMany, but runs in a worker isolate.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited