startStepTracking method

  1. @override
Future<bool> startStepTracking()
override

Starts step tracking on iOS devices.

Initializes the tracking session by setting the tracking flag, recording the session start time, and resetting the session step count. Fetches the current total steps from the system and stores them as the session's starting step count. Persists all relevant data and starts the auto-save mechanism. Displays a notification to indicate that step tracking has started, and emits an update event.

Returns true if tracking was successfully started or is already active.

Returns a Future that completes with a boolean indicating the success of the operation.

Implementation

@override
Future<bool> startStepTracking() async {
  if (_isTracking) return true;

  _isTracking = true;
  _sessionStartTime = DateTime.now();
  _sessionSteps = 0;
  await fetchTotalStepsFromSystem();
  _sessionStartTotalSteps = _totalStepsFromSystem;
  _lastSavedTotalSteps = _totalStepsFromSystem;

  await _persistAllData();
  _startAutoSave();

  if (_config.enableTrackingNotification) {
    _notificationUtilsIOS.showStartTrackingNotification(
      notificationTitle: _config.trackingNotificationTitle,
      notificationContent: _config.trackingNotificationContent,
    );
  }

  _emitUpdate();
  return true;
}