Skip to content

Instantly share code, notes, and snippets.

@praveeno
Created October 22, 2021 08:22
Show Gist options
  • Save praveeno/6971c7c0fe129a0b9ea36646c29b4146 to your computer and use it in GitHub Desktop.
Save praveeno/6971c7c0fe129a0b9ea36646c29b4146 to your computer and use it in GitHub Desktop.
// get location to api
//
class FoodCartController {
final List positions = [];
constructor() {
final service = singltonService();
service.initState()
}
}
singltonService() {
List positions = [];
syncServer(position) {
try {
sendToServer(data)
.then((response) {
positions = [];
});
} catch (e){
snackBar.showMessage(e.message, 2000);
}
}
initState() {
getDeviceLocation().listen((location) {
if (DeviceNetworkStatus == DeviceStatus.Online) {
List data = [];
if (positions.isNotEmpty) {
data = positions;
}
data.add(location);
syncServer(data);
} else {
positions.add(location);
}
});
}
sendToServer() {
try {
await http.post(url, {body: positions});
} catch (e) {
// handle error here.
rethrow;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment