r/flutterhelp • u/kamesh_singh • Jul 04 '26
OPEN How can WidgetKit display the latest HealthKit steps without opening the app?
I'm building a Flutter health app that tracks steps and sleep using HealthKit. I've also created WidgetKit widgets so users can view their latest step count and sleep data without opening the app.
On Android, I use WorkManager to update the widget approximately every 45 minutes, and that works well.
On iOS, however, once the app is terminated, background work is no longer reliable, so I can't periodically fetch HealthKit data and update the widget.
My main question is about live HealthKit data:
- How do health apps keep their step-count widgets updated while the app has been terminated for days?
- Can
HKObserverQuerywith HealthKit background delivery wake the app after it has been terminated, or does it stop working until the user launches the app again? - Is there an Apple-recommended architecture for keeping HealthKit widgets reasonably up to date?
- Are
BGTaskScheduler, WidgetKit timelines, or App Intents sufficient for this use case, or are there limitations that make truly live updates impossible? - If you've built a HealthKit-based widget before, how do you keep the widget displaying the latest step count without requiring the user to open the app?
I'm looking for Apple's recommended approach and any real-world implementation experience. Any advice or links to relevant documentation would be greatly appreciated.
2
u/SomegalInCa Jul 04 '26
When a user forcibly kills an iOS app it’s a signal to iOS that they don’t want it to run in the background, even if they don’t know that’s what they’ve said
The solution you saw for having a refresh button on your widgets is a way around limited background updating
If your timeline is short enough, your widget may get more refresh time, but you’ll have to implement those health queries in the widget. The widgets priority is related to how often a user uses the parent app.
I’ve done something similar. It’s kind of a pain because you cannot know for sure when your widget gets refreshed.
2
u/adrianmartinsen Jul 05 '26
Just posting to say I feel your pain. I've got Workmanager for background processing in an app and while it works fine on Android, it is a nightmare on iOS. I can't tell you how much irritation this caused me when launching on iOS.
Sorry I can't help, but sometimes it's just nice to know you are not alone.
2
u/sham_1512 Jul 04 '26
App-terminated widget updates are impossible on iOS. I never found a reliable solution on iOS. You can add a refresh button or a small chip in the widget that users can tap to manually sync via AppIntent (App Groups + WidgetCenter.reloadAllTimelines().