Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if data was successfuly written to firebase in flutter

I need to check if data was written successfuly to Firestore so if it was successful I need to show a popup showing data was written or if data wasn't written i need to show a popup showing task failed so should I use a future builder what is the way to do it

like image 657
Naruto Beliveit Avatar asked Oct 27 '25 12:10

Naruto Beliveit


1 Answers

Every Firestore Operations are promises, so it has .then() and .catch() method to handle whether the task is successful or failure.
For example, you can do something like this.

 firestoreInstance.collection("Users").document('123456').updateData({
 
  "username" : 'white_devil'

 }).then((result) {
   
   print("Success!");

 }).catch((error){
 
   print("Error!")

});

Not only on updateData(), you can also use this case in setData(),add(),get(), getDocuments() and all operations which returns a promise.

like image 79
Shri Hari Avatar answered Oct 30 '25 02:10

Shri Hari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!