vedartm / paginate_firestore

A flutter package to simplify pagination with firestore data 🗃
https://pub.dev/packages/paginate_firestore
MIT License
113 stars 138 forks source link

StreamSubscription needs to be closed #59

Closed fer-ri closed 3 years ago

fer-ri commented 3 years ago

Hi

Thanks for your package. It saves a lot of my time :+1:

Btw, I noticed that when using isLive option as true, the stream is always active even we moved into another screen.

We need to capture the StreamSubscription from this line https://github.com/excogitatr/paginate_firestore/blob/master/lib/bloc/pagination_cubit.dart#L86 and cancel() on dispose.

Something like this


List<StreamSubscription<QuerySnapshot>>() streams = List<StreamSubscription<QuerySnapshot>>();

...

_getLiveDocuments() {
    ...
      StreamSubscription listener = localQuery.snapshots().listen((querySnapshot) {
        _emitPaginatedState(
          querySnapshot.docs,
          previousList:
              loadedState.documentSnapshots as List<QueryDocumentSnapshot>,
        );
      });
    }

  streams.add(listeners);
  }

...

streams.forEach((listener) => listener.cancel());

Thanks

vedartm commented 3 years ago

Thanks for making a PR @ghprod. I will be released with the next version. Feel free to reopen it if you face a similar issue.