我每秒都在计时器中调用健康包,但它没有更新从 ios 健康工具包中获取的步数值我必须重新打开应用程序或在 ios 健康应用程序和我的应用程序之间切换
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;
}
它正在工作但不是实时更新 所有权限已授予