0

I have two separate screen home.dart and track.dart

In home.dart

location.getLocation()

In track.dart I'm listening location

location.onLocationChanged.listen((LocationData loc) { // do something })

When I navigate to track.dart screen and return to home.dart location.getLocation doesn't return any data and not giving any error at all.

How can I implement such feature and what is the best solution for this problem.

Flatform: android Flutter location version: 4.3.0

ammasum
  • 118
  • 1
  • 9
  • Can you share the code sample? Where do you call `location.getLocation()` ? – David L. Apr 10 '22 at 13:09
  • Calling after initState – ammasum Apr 10 '22 at 17:32
  • If you're calling it somewhere within `initState`, then that's probably why. Unless you're pushing a new home screen on the Navigator stack, your home screen already exists, and any code that's called in `initState` is only triggered once, when the widget is created. You probably want to move that code to `didChangeDependencies` instead. – David L. Apr 11 '22 at 18:30
  • @DavidL. I have check and confirm that location.getLocation() being calling. – ammasum Apr 11 '22 at 20:51

0 Answers0