A flutter project to provide Geo Fence functionality in Android and IOS
Android
In your AndroidManifest.xml you should add the following lines:
final geoFenceService = GeoFenceService()
geoFenceService.startService({
///Latitude of the fence center
fenceCenterLatitude: _fence_latitude,
///Longitude of the fence center
fenceCenterLongitude: _fence_longitude,
///Radius in meter which indicates how much area will be covered by Fence
radius: fence_area,
})
geoFenceService.stopFenceService()
Status status = geoFenceService.getStatus()
Position? position = geoFenceService.getCurrentLocation()
geoFenceService.geoFenceStatusListener.listen((geoFenceStatus) => {
///here geoFenceStatus will be listened whenever user enters or exit
})
Important: As the geoFenceStatusListener is a stream so do not forgot to cancel it when the widget gets dispose().
Note: This library doesn't work when the app is in the background.
Reference: This library uses GeoLocator internally