【发布时间】:2020-08-12 14:34:57
【问题描述】:
我想在后台更新用户的位置。
为了在后台执行任务,我使用了这个包 workmanager。 链接:https://pub.dev/packages/workmanager
但我无法更新位置,似乎无法使用异步代码?
这是我的代码,
void callbackDispatcher() {
Workmanager.executeTask((task, inputData) async {
await _HomeScreenState().updateUserLoc();
print('it is working?');
return Future.value(true);
});
}
//Inside my stateFul Widget,
void initState() {
super.initState();
Workmanager.initialize(
callbackDispatcher,
isInDebugMode: true,
);
Workmanager.registerPeriodicTask(
"1",
fetchBackground,
frequency: Duration(minutes: 15),
);
}
updateUserLoc() async {
print("executi9ng the updateUserLocccccc");
await getusersLocation();
print("executi9ng the updateUserLoc");
GeoFirePoint point = geo.point(latitude: lat, longitude: long);
_firestore.collection('locations').document(widget.userid).setData(
{'position': point.data},
merge: true,
);
}
有没有其他方法可以在后台更新用户的位置?
【问题讨论】:
标签: android firebase flutter dart