title: Flutter Firestore Pagination (add/remove items)
body: <p>I'm struggling to get this done, after two days I decided to ask you guys for help.
  I'm using Mobx as state management, the issue is related to adding/removing an item to/from the list, e.g. if I retrieve two queries of 5 items each, according to the limit and then remove an item from the first query the first item from the second query is duplicate and if I add a new item, the first item from the second query is hidden. I have also set a scrollListener to the ListView.builder to get the bottom of the list and call for more items.</p>
  <p>Thanks in advance,</p>
  <pre><code>@override
    Stream&lt;QuerySnapshot&gt; teste(DocumentSnapshot lastDoc) {
      if (lastDoc == null) {
        return firestore.collection('teste')
        .orderBy('name')
        .limit(5)
        .snapshots();
      } else {
        return firestore.collection('teste')
        .orderBy('name')
        .limit(5)
        .startAfterDocument(lastDoc)
        .snapshots();
      }
    }
  
    @observable
    ObservableList&lt;List&lt;TesteModel&gt;&gt; allPagedResults = ObservableList&lt;List&lt;TesteModel&gt;&gt;();
  
    @observable
    ObservableList&lt;TesteModel&gt; listTeste = ObservableList&lt;TesteModel&gt;();
  
    @observable
    DocumentSnapshot lastDoc;
  
    @observable
    bool hasMoreItem;
  
    @action
    void teste() {
      var _currentRequestIndex = allPagedResults.length;
      
      primaryRepository.teste(lastDoc).listen((query) {
        if (query.docs.isNotEmpty) {
          var _query = query.docs.map((doc) =&gt; TesteModel.fromFirestore(doc))
          .toList();
  
          var _pageExists = _currentRequestIndex &lt; allPagedResults.length;
  
          if (_pageExists) allPagedResults[_currentRequestIndex] = _query;
          else allPagedResults.add(_query);
  
          listTeste = allPagedResults.fold&lt;List&lt;TesteModel&gt;&gt;(&lt;TesteModel&gt;[],
            (initialValue, pageItems) =&gt; initialValue..addAll(pageItems)).asObservable();
  
          if (_currentRequestIndex == allPagedResults.length - 1) lastDoc = query.docs.last;
          
          hasMoreItem = _query.length == 5;
        }
      });
    }
  </code></pre>