Reputation: 31
Every time I enter a bank information, I need to check if the name is correct, because I want this feature to work offline, so I can not have inconsistencies in the bank. So far as the code below is working the way I want. but in only one situation does the sync fail, which is when I press the app's back button until it closes. So when I turn on the internet the data is not synchronized.
Firestore.instance
.collection('Regiao')
.where('idRegiao', isEqualTo: idRegiao)
.snapshots()
.listen((data){
data.documents.forEach((doc) {
Firestore.instance
.collection('CadernoCampoDefensivo')
.document(idCadernoCampo)
.updateData({'regiao' : doc['nomeRegiao']})
.then((_){});
});
});
Upvotes: 0
Views: 411
Reputation: 599686
The code in your app only runs when the user is actively using your app. That is working as expected, as otherwise any application could be doing whatever it wants when the app is not active, and battery life would suffer.
If this code needs to run in a single place, to respond to other users updating the data, then inside your phone is typically not the best place to do that. Instead consider running this on a server you control, or in Cloud Functions for Firebase. These solve the problem of both connectivity (they're much more likely to be connected to the network than a phone is), and of battery life (as they're connected to a mains power source).
Upvotes: 1