Flutter remove firebase database Listener. You can use the below example code:
1 2 3 4 5 | var sub1 = databaseReference.onChildAdded.listen(_onEntryAdded); var sub2 = databaseReference.onChildChanged.listen(_onEntryChanged); sub1.cancel(); sub2.cancel(); |
If you have this code in a widget you can use:
1 2 3 4 5 6 | @override void dispose() { super.dispose(); sub1?.cancel(); sub2?.cancel(); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.