I'm using the objectbox with watch feature. But if I use watch feature I cant close the store, Can I have any problem about this? with battery low or slow app? is there a better way to do it?
My code
Stream<List<Room>>> listenRoomUnreadMessage(){
try {
return objectBox.store
.box<RoomUnread>()
.query()
.watch(triggerImmediately: true)
.transform(
StreamTransformer.fromHandlers(
handleData: (query, sink) =>
sink.add(query.find().map((e) => e.toDomain()).toList()),
),
);
} catch (ex) {
rethrow;
}
}
and create store class
class ObjectBox {
late final Store store;
ObjectBox._create(this.store);
static Future<ObjectBox> create() async {
final store = await openStore();
return ObjectBox._create(store);
}
}
and I call create in main function
late ObjectBox objectBox;
void main() async {
objectBox = await ObjectBox.create();
runApp(const MaterialAppMain());
}
Thanks