'Will Firestore's listen function listen twice if it is run twice?

i have this listen function

Future listening()async{
FirebaseFirestore.instance.collection("users").snapshots().listen((dodo) {
 //actins
});
}

and i call it by the following

 TextButton(
                      
  onPressed:(){
    listening();                  
  } , 
   child: Text('tab me')
   )

ok now i know if it been called so it will listen to events until it is canceled

but the the question is what if I tab the button twice. means i call the same function twice . Will it listen twice and cause memory leak ? Or is that nothing to worry about?



Solution 1:[1]

Generally, you should call a snapshot only once, otherwise firebase charges you for every ‘read’ attempt you do.

In your case, you could solve this simply by:

bool isListening = false;
OnPressed: (){
   If(isListening) return;
   isListening = true;
   Listening();
}

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Aron