0

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

Renato
  • 13
  • 4
  • is there any error message or so that you can share? What means, you cannot close the store? – w461 Sep 21 '22 at 07:36

0 Answers0