Created
October 22, 2021 08:22
-
-
Save praveeno/6971c7c0fe129a0b9ea36646c29b4146 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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