stopStepTracking method

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

Stops the step tracking session.

This will:

  1. Save current session if steps were recorded
  2. Update tracking state
  3. Cancel subscriptions
  4. Stop background services

Returns true if successful, false otherwise

Implementation

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

  try {
    // Save current session if steps were recorded
    if (_sessionSteps > 0) {
      await _saveCurrentSession();
    }

    // Update tracking state
    _isTracking = false;
    await _prefs.setBool('isTracking', false);
    await _prefs.setInt('initialSteps', -1);
    await _prefs.setInt('sessionSteps', 0);

    // Clean up resources
    await _stepCountStream?.cancel();
    _stepCountStream = null;
    await BackgroundService.stop();
    await NotificationUtils.cancelNotification();

    _emitUpdate();
    return true;
  } catch (e) {
    debugPrint('Error stopping step tracking: $e');
    return false;
  }
}