stopStepTracking method
Stops the step tracking session.
This will:
- Save current session if steps were recorded
- Update tracking state
- Cancel subscriptions
- 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;
}
}