step_logger 1.0.0-beta.4
step_logger: ^1.0.0-beta.4 copied to clipboard
A Flutter plugin for step counting and log sessions with background service support for Android and iOS.
Step Logger πΆββοΈ #
A Flutter plugin for cross-platform step tracking with background support.
Features #
- π Real-time step counting
- π Background service for continuous tracking (Android)
- π Historical session data storage
- π Customizable notification
- π± Works in foreground and background
- π Automatic session recovery after app kills
Platform Support #
Feature | Android | iOS |
---|---|---|
Real-time steps | β | β |
Background tracking | β | β οΈ Limited |
Session history | β | β |
Step accuracy | High | High |
Battery impact | Moderate | Low |
Android Setup #
Permissions βοΈ #
Add to android/app/src/main/AndroidManifest.xml
:
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.BODY_SENSORS" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<!-- For Android 9+ background execution -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_HEALTH" />
Service declaration #
<service
android:name="com.transistorsoft.flutter.backgroundfetch.BackgroundFetchService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true" />
<service
android:name="id.flutter.flutter_background_service.BackgroundService"
android:foregroundServiceType="health"/>
<service
android:name="com.your.example_app.ForegroundService"
android:enabled="true"
android:exported="false" />
iOS Setup #
Requirements #
-
Add HealthKit entitlement:
- In Xcode, go to your target's Signing & Capabilities.
- Click "+" and add HealthKit.
-
Add these entries to your
Info.plist
:
<key>NSHealthShareUsageDescription</key>
<string>We need access to HealthKit to track your steps</string>
<key>NSHealthUpdateUsageDescription</key>
<string>We need access to HealthKit to save your step data</string>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>healthkit</string>
</array>
<!-- Notification-->
<key>NSUserNotificationAlertStyle</key>
<string>alert</string>
iOS Limitations #
β οΈ Important iOS Considerations
-
Background step updates require explicit user permission.
-
Steps are only recorded when:
- The app is in the foreground.
- The user has HealthKit background delivery enabled.
- The user opens the app periodically (to sync latest data).
-
Step data accuracy depends on the device
-
Sessions interrupted by app kills will:
- Persist tracking state.
- Recover steps when the app relaunches.
- Auto-stop sessions older than 12 hours.
Note: iOS does not support true background step tracking services like Android. The plugin uses HealthKit background delivery as a workaround, which depends on system scheduling and user permissions. This means background updates may be delayed or less frequent compared to Android, and step counts are calculated when the app is brought to the foreground.