'Flutter snapshot duplicating Issue

I am working with firestore to listen to every incoming request. And I am using getx as state management for the project. Every pending request fetch from the firestore will be converted to a list of unaccepted request.

What I want to achieve is when there is no longer pending request in my list. I want go back to my homescreen.

The problem is that the method that navigate to my home screen is executed twice

void initState() {
listenToUnAccepteRequest();
super.initState();

}enter image description here

void listenToUnAccepteRequest() async {

requestcollecctionrefference
    .where('status', isEqualTo: 'pending')
    .snapshots()
    .listen((querySnapShot) {

  requestxcontroller.lisofunacceptedrequest(querySnapShot.docs.map((e) {
    var request = RequestDetails.fromJson(e.data() as Map<String, dynamic>);
    request.request_id = e.id;
    return request;
  }).toList());

  if (requestxcontroller.lisofunacceptedrequest.length == 0 &&
      requestxcontroller.hasongingtrip == false) {
       Get.offNamed(HomeScreenManager.screenName);
  }

});

} The effect of the screen look like this



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source