I am calling health package in a timer each second but it is not updating the steps value fetched from ios health kit i have to either reopen the app or switch between ios health app and my app
Timer.periodic(const Duration(seconds: 1), (timer) async {
todaySteps.value = await GoogleFitController.getSteps() ?? 0;
});
static Future<int?> getSteps() async {
HealthFactory health = HealthFactory();
int? steps;
var now = DateTime.now();
var midnight = DateTime(now.year, now.month, now.day, 0);
try {
steps = await health.getTotalStepsInInterval(midnight, now);
} catch (e) {
print("steps error ====== ${e.toString()}");
}
print("steps from google fit foreground ===== = == = = === $steps");
return steps;
}
it is working but not updating in real time all the permission has been granted