useGeolocation function

GeolocationState useGeolocation({
  1. LocationSettings? locationSettings,
})

Tracks the state of user's geographic location using geolocator(ref link). ref link

Implementation

GeolocationState useGeolocation({
  LocationSettings? locationSettings,
}) {
  final state = useRef(const GeolocationState());
  final positionChanged = useStream(useMemoized(
      () => Geolocator.getPositionStream(locationSettings: locationSettings)));

  state.value = GeolocationState(
    fetched: positionChanged.hasData,
    position: positionChanged.data,
  );

  return state.value;
}