Skip to content

Latest commit

History

63 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Author's Note: this plugin is not officially supported and is meant to be used as an example. Please feel free to pull it into your own projects, but there is no official version hosted on pub.dev and support may be limited. If you run into any issues running this sample, please file an issue or, even better, submit a pull request!

What is geofencing? here

Geofencing

A sample geofencing plugin with background execution support for Flutter.

Getting Started

This plugin works on both Android and iOS. Follow the instructions in the following sections for the platforms which are to be targeted.

Android

Add the following lines to your AndroidManifest.xml to register the background service for geofencing:

<receiverandroid:name="io.flutter.plugins.geofencing.GeofencingBroadcastReceiver"android:enabled="true"android:exported="true"/>
<serviceandroid:name="io.flutter.plugins.geofencing.GeofencingService"android:permission="android.permission.BIND_JOB_SERVICE"android:exported="true"/>

Also request the correct permissions for geofencing:

<uses-permissionandroid:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permissionandroid:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

Finally, create either Application.kt or Application.java in the same directory as MainActivity.

For Application.kt, use the following:

classApplication : FlutterApplication(), PluginRegistrantCallback {
overridefunonCreate() {
super.onCreate();
GeofencingService.setPluginRegistrant(this);
}
overridefunregisterWith(registry:PluginRegistry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}

For Application.java, use the following:

publicclassApplicationextendsFlutterApplicationimplementsPluginRegistrantCallback {
@OverridepublicvoidonCreate() {
super.onCreate();
GeofencingService.setPluginRegistrant(this);
}
@OverridepublicvoidregisterWith(PluginRegistryregistry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}

Which must also be referenced in AndroidManifest.xml:

 <applicationandroid:name=".Application"
...

iOS

Add the following lines to your Info.plist:

<dict>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>YOUR DESCRIPTION HERE</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>YOUR DESCRIPTION HERE</string>
...

And request the correct permissions for geofencing:

<dict>
...
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>location-services</string>
<string>gps</string>
<string>armv7</string>
</array>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
...
</dict>

Need Help?

For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

About

Rough work for Flutter geofencing plugin

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages