应用程序用于测量步数,目标是如果它不小心关闭,在此之前它会向服务器发送请求以保存步数。
应用程序关闭导致应用程序无法向服务器发送数据,如何解决?
应用程序似乎没有时间。
case AppLifecycleState.detached:
var steps =
Provider.of<StepsProvider>(context, listen: false).getTotalSteps;
if (steps != '0') {
//Yup, the code works here, but don't have time to send requests to the server or save local storage data.
await StepsBackUp(steps: steps).saveBackUpSteps(); // same for local storage
await PedometerService(steps: steps).saveRecord();
}
break;