title: Firestore snapshot listener data duplication issue in flutter
body: <p>Hello i am working with fire store database for making one to one chat between user. Here i want some pagination of messages. So i called snapshot listener inside <strong>initState</strong> So the problem is while i navigate to chat screen, <strong>initState</strong>  called snapshot listener <strong>DocumentType.added</strong> automatically. so data becomes duplicate..</p>
  
  <p>here is my code which i called inside <strong>initState</strong></p>
  
  <pre><code>List&lt;DocumentSnapshot&gt; _products = [];
  StreamController&lt;List&lt;DocumentSnapshot&gt;&gt; _streamController =
  StreamController&lt;List&lt;DocumentSnapshot&gt;&gt;.broadcast();
  
  @override
  void initState() {
       db
      .collection('chat')
     .document(docId)
      .collection('messages')
      .orderBy('timestamp', descending: true)
      .snapshots().listen((data) =&gt; onChangeData(
            data.documentChanges,
          ));
  }
  void onChangeData(
    List&lt;DocumentChange&gt; documentChanges,
  ) {
    documentChanges.forEach((productChange) {
      if (productChange.type == DocumentChangeType.removed) {
        _products.removeWhere((product) {
          return productChange.document.documentID == product.documentID;
        });
  
        _streamController.add(_products);
      }
      if (productChange.type == DocumentChangeType.added) {
      _products.insert(productChange.newIndex, productChange.document);
        _streamController.add(_products);
      }
      if (productChange.type == DocumentChangeType.modified) {
        int indexWhere = _products.indexWhere((product) {
          return productChange.document.documentID == product.documentID;
        });
  
        if (indexWhere &gt;= 0) {
          _products[indexWhere] = productChange.document;
        }
  
        _streamController.add(_products);   
      }
    });
  }
  </code></pre>