setActivityLevel method

void setActivityLevel(
  1. ActivityLevel? activityLevel
)

Sets the user's activity level and updates the recommended calorie target if needed.

Implementation

void setActivityLevel(ActivityLevel? activityLevel) {
  // If the new activity level is the same as the current one, do nothing.
  if (_activityLevel == activityLevel) return;
  // Set the new activity level.
  _activityLevel = activityLevel;
  // Recalculate the recommended calorie target.
  int calories = _calculateRecommendedCalorie();
  if (calories > 0) {
    // Update the calorie target if it's positive.
    caloriesTarget = calories;
  }
}