Skip to main content

accurate_step_counter 4.0.0 copy "accurate_step_counter: ^4.0.0" to clipboard
accurate_step_counter: ^4.0.0 copied to clipboard

PlatformAndroid

Android step counter using hardware sensors and a health foreground service, with live totals, SQLite history, reboot recovery, and optional merge policies.

Changelog #

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

4.0.0 - 2026-10-25 #

Breaking #

  • Return to Android-only tracking. Remove the experimental HealthKit detector and health dependency. Unsupported tracking platforms throw UnsupportedError.
  • stop() flushes and stops auto-logging. Use startTracking() to resume the complete pipeline.
  • Deprecate the synchronous legacy reset(); it fails clearly for hardware daily totals. Use stop, clear logs, and reset native state for an explicit reset.
  • Fail clearly for missing activity permission or a hardware service that cannot start. Continuous counting uses a health service without a data-sync fallback.
  • Align the Flutter SDK minimum with Dart 3.9 (Flutter 3.35).

Added #

  • Automatic lifecycle observation and shared concurrent/repeated startTracking.
  • Native cadence limits in StepDetectorConfig; running uses 240/minute and 14,400/hour while walking retains 180/minute and 9,000/hour.
  • Android acceptance matrix and a package verification record.
  • Dart and JVM regression checks for the actual package integration and native restore/rotation rules.

Fixed #

  • New-day floors and aggregate baselines, current-date stream queries, original date attribution for cold-start history, and stale queries completing at midnight.
  • Shared native event-channel ownership, first logged delta, repeated equal-sized recovery gaps, concurrent imports, and double-counted session totals on import.
  • Keep displayed/stored floors out of the raw sensor logging stream; preserve distinct external imports during native startup and historical reconciliation.
  • Retain buffered storage operations on write failure and register plugins in the database isolate; acknowledge isolate shutdown before terminating it.
  • Persist native offsets, floors, and actual rotation timestamps across process restarts; preserve valid counter batches without impossible detector evidence.
  • Validate delayed screen-off batches against the whole elapsed interval and persist rejected increments so a restart cannot resurrect discarded steps.
  • Wait for sensor registration before reporting startup success; preserve explicit stop/logout across reboot.

3.1.0 - 2026-07-28 #

Added #

  • iOS support via HealthKit (health package) with filtered step reads and step smoothing.
  • New internal IosHealthStepDetector service that emits realtime step events from Health app totals.
  • Cross-platform example flow now handles iOS initialization cleanly.

Changed #

  • watchTodaySteps() remains immediate and floor-protected while now supporting iOS live step source.
  • Package positioning updated from Android-only to Android + iOS HealthKit.

Fixed #

  • Native event merge now always applies floor protection before emitting (prevents downward jitter on transient resets).
  • Rotation drain persists previous day totals into SQLite with date anchoring.

3.0.0 - 2026-07-26 #

Breaking #

  • Primary detection is now TYPE_STEP_COUNTER FGS on all Android API 24+ (including Samsung). Previous API≤29 / non-Samsung gate removed.
  • SmartMergeHelper.mergeStepCounts semantics changed — no longer naive max(). Uses StepLogic (HC duplication band, sensor overcount at 1.10×, HC can correct downward, server floor). Prefer SmartMergeHelper.merge() for full MergeDecision flags.
  • Legacy auto-start of StepCounterForegroundService on app termination is off by default to prevent dual-FGS fights.
  • StepDetectorConfig.useForegroundServiceOnOldDevices defaults to false (legacy sensors_plus fallback only).

Added #

  • Production-hardened StepCounterService: prefs persist, reboot detect, burst/minute/hour caps with baseline fold-in, vehicle/bicycle Activity Recognition filter, TYPE_STEP_DETECTOR cross-check, exact midnight alarm, BootReceiver, TimeChangeReceiver, rotation stamps
  • ActivityClassifier + soft-fail without Play Services (play-services-location)
  • Dart policies: StepLogic, MergePolicy, smoothHcReading, RotationGuard, StepRateLimiter
  • Platform APIs: setNotificationDisplay, forceUpdateTodaySteps, consumeLastRotation, resetNativeStepState
  • startTracking() — one-call setup (DB + FGS + aggregated logging)
  • Short aliases: isBatteryOptimized(), requestBatteryOptimization()
  • Safe calibration from SQLite today (sensor=0, seed ≤40k) on start
  • Native↔SQLite reconcile on aggregated start (fixes undercount after process death)
  • Rotation drain on start / resume / step stream
  • Ported production policy unit tests under test/policy/
  • Soft uses-feature for stepcounter/stepdetector (required=false)
  • Consumer ProGuard keep rules for services/receivers

Fixed (production DX / hardening) #

  • Skip legacy terminated-prefs sync when the native FGS is available (no dual recovery)
  • Example + verification check TYPE_STEP_COUNTER FGS, not fallback detector
  • Removed 500ms artificial delay from initSteps (now aliases startTracking)
  • Collapsed duplicate getTodaySteps / getYesterdaySteps definitions
  • Cold-start day-gap restore stamps KEY_LAST_ROTATION_* and persists rotated prefs
  • Activity Recognition PendingIntent uses explicit component + unique request code; receiver in manifest
  • Removed Play-risk permissions USE_EXACT_ALARM, BODY_SENSORS, BODY_SENSORS_BACKGROUND, HIGH_SAMPLING_RATE_SENSORS
  • Plugin no longer permanently registers a second TYPE_STEP_COUNTER listener (battery)
  • Kotlin unit test matches real MethodChannel API
  • NotificationChannel creation guarded for API 24–25 (StepCounterService)
  • dispose() / stopLogging() flush write buffer and cancel flush timer

Migration #

  1. Bump to ^3.0.0 and request ACTIVITY_RECOGNITION + notifications before startTracking().
  2. Prefer await steps.startTracking() over the old three-call sequence.
  3. If you relied on naive max merge, switch to SmartMergeHelper.merge(...) and handle MergeDecision.
  4. Keep notification synced with setNativeNotificationDisplay(merged) — do not force-write merged HC into sensor baseline.
  5. Supply HC/server yourself (BYO); package does not embed Health Connect SDK.

2.0.0 - 2026-02-28 #

Major: Native Step Service + Smart Merge #

This release promotes the native TYPE_STEP_COUNTER foreground service as the primary detection strategy and adds the SmartMergeHelper utility for combining multiple step sources.

Added #

  • SmartMergeHelper — combine sensor + Health Connect + server (naive max in 2.x)
  • Native Step Service Status API — isNativeStepServiceRunning(), isUsingNativeStepService

Changed #

  • VERSION BUMP to 2.0.0
  • README rewritten for TYPE_STEP_COUNTER architecture

Fixed #

  • StepCounterService.kt — added isRunning flag

Removed #

  • Stale Hive artifacts

1.9.5 - 2026-02-22 #

Fixed #

  • Background isolate sqflite initialization error — Added DartPluginRegistrant.ensureInitialized() to isolate entry point

1.9.4 - 2026-02-22 #

Added #

  • Terminated sync gap reconciliation with idempotent deterministic gap keys
  • Single-flight terminated sync to prevent concurrent reprocessing
  • Production example flow in example app

1.9.3 - 2026-02-03 #

Added #

  • Automatic 30-day log retention policy
  • Database write batching (3-second buffer)
  • Background isolate for database operations (StepRecordConfig.lowEndDevice())
  • Stream emission throttling (max 10Hz)

1.9.2 - 2026-02-03 #

Fixed #

  • Samsung ANR mitigation (auto-disables foreground service on Samsung Android 11+)
  • Midnight step distribution across day boundaries
  • Async database logging (moved to non-blocking operations)

Removed #

  • device_info_plus dependency (replaced with native platform channel)

1.9.1 - 2026-01-28 #

Verified #

  • ANR-safe architecture audit: all Kotlin I/O on Dispatchers.IO, async SharedPreferences, background SQLite

1.9.0 - 2026-01-28 #

Changed #

  • Database migration: Hive → sqflite — Indexed SQL queries, smaller footprint, no code generation needed

Removed #

  • Hive dependencies (hive, hive_flutter, hive_generator, build_runner)

1.8.12 and earlier #

See git history for pre-1.9.0 notes.

4
likes
150
points
630
downloads

Documentation

API reference

Publisher

verified publisherrahulsha.com.np

Weekly Downloads

Android step counter using hardware sensors and a health foreground service, with live totals, SQLite history, reboot recovery, and optional merge policies.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, path, sensors_plus, sqflite

More

Packages that depend on accurate_step_counter

Packages that implement accurate_step_counter