increment method
Increments the counter by amount
(default is 1).
This method increases the current counter value by the specified amount
.
It ensures that the operation is thread-safe by using a lock.
Returns the updated counter value.
Implementation
Future<int> increment([int amount = 1]) {
return _lock.synchronized(() async {
final current = await get(); // already calls _ensureFresh inside lock
final updated = current + amount;
await value.set(updated);
return updated;
});
}