Skip to content

Commit

Permalink
Fix location not showing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dewmal committed Mar 23, 2020
1 parent 7ca22ee commit e63d5fe
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions lib/page/screen/case_details_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,26 @@ class CaseDetailScreenState extends State<CaseDetailScreen> {
Timer _currentLoctimer;
bool _isInitialLocationAdded = false;

Future<void> updateLocation() async {
List<Location> newEntries = await getLocationUpdate();
print("LOCATIONS Fetched: ${newEntries.length}");
if (this.mounted) {
setState(() {
newEntries.forEach((e) {
if (!entries.contains(e)) {
entries.add(
e); //location id should be used here to prevent duplicate locations from being added
}
});
print("POLLED locations: ${newEntries.length}");
});
}
}

@override
void initState() {
super.initState();
updateLocation();

WidgetsBinding.instance.addPostFrameCallback((_) {
_channel.invokeMethod('requestLocationPermission').then((res) {
Expand All @@ -38,19 +55,7 @@ class CaseDetailScreenState extends State<CaseDetailScreen> {

_locationTimer = Timer.periodic(Duration(minutes: 5), (timer) async {
print("POLLING the locations");
List<Location> newEntries = await getLocationUpdate();
print("LOCATIONS Fetched: ${newEntries.length}");
if (this.mounted) {
setState(() {
newEntries.forEach((e) {
if (!entries.contains(e)) {
entries.add(
e); //location id should be used here to prevent duplicate locations from being added
}
});
print("POLLED locations: ${newEntries.length}");
});
}
await updateLocation();
});

_currentLoctimer = Timer.periodic(Duration(seconds: 2), (_) {
Expand Down

0 comments on commit e63d5fe

Please sign in to comment.