incrementProgress method

void incrementProgress(
  1. String achievementId,
  2. int amount
)

Adds amount to achievementId's progress. Safe to call after the achievement is already completed: progress keeps accumulating, isCompleted stays true, never throws or "re-unlocks".

Implementation

void incrementProgress(String achievementId, int amount) {
  _validateId(achievementId);
  if (amount <= 0) {
    throw ArgumentError.value(amount, 'amount', 'must be greater than 0');
  }
  final current = _progressMap[achievementId] ?? 0;
  if (amount > _maxInt - current) {
    throw RangeError('progress overflow for $achievementId');
  }
  final wasCompleted = isCompleted(achievementId);
  _progressMap[achievementId] = current + amount;
  if (!wasCompleted && isCompleted(achievementId)) {
    _unlockController.add(achievementId);
  }
  _scheduleSave();
}