Skip to content
Advertisement

Why counter just increase to 1 in firebase?

im trying to increase a visitor counter views when access to read a message, so i made a method called incrementar () and set it where i retrieve info when someone click to open that post. But i dont know why only increase to 1 view in firebase, if i click again it does not increase. should use shared preferences? or there is an other method to increase a counter from firebase?

JavaScript

}

Thanks so much

Advertisement

Answer

You’re setting +1 as the value each time you call:

JavaScript

What would work is:

JavaScript

Instead of sending the literal value 1, this second snippet sends an instruction to increment the current value by 1.

Advertisement