geofence 1.0.3
geofence #
This plugin help get geofence notification
Getting Started #
Android #
Add the following lines to your AndroidManifest.xml to register the background service for geofencing:
<receiver android:name="com.webstersys.geofence.geofence.GeofenceBroadcastReceiver"
android:enabled="true"
android:exported="true" />
<service android:name="com.webstersys.geofence.geofence.GeofenceTransitionsJobIntentService" android:enabled="true" android:exported="true"
android:permission="android.permission.BIND_JOB_SERVICE"/>
<receiver android:name="com.webstersys.geofence.BootDeviceReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
Also request the correct permissions for geofencing:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
Finally, create either Application.kt or Application.java in the same directory as MainActivity.
For Application.kt, use the following:
class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate();
GeofenceTransitionsJobIntentService.setPluginRegistrant(this)
}
override fun registerWith(registry: PluginRegistry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
For Application.java, use the following:
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@Override
public void onCreate() {
super.onCreate();
GeofenceTransitionsJobIntentService.setPluginRegistrant(this);
}
@Override
public void registerWith(PluginRegistry registry) {
GeneratedPluginRegistrant.registerWith(registry);
}
}
Which must also be referenced in AndroidManifest.xml:
<application
android:name=".Application" />
0.0.1 #
- Added Geofence Flutter Plugin With Only Android Support
##1.0.2
*Gradle version updated
##1.0.3 *Notification part commented
geofence_example #
Demonstrates how to use the geofence plugin.
Getting Started #
import 'dart:isolate';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:geofence/geofence.dart';
import 'package:geofence/geofence_event.dart';
import 'package:geofence/geofence_region.dart';
import 'package:geofence/location.dart';
void main() => runApp(new MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
@override
void initState() {
super.initState();
// initPlatformState();
initGeofence();
}
static void callback(Location l, GeofenceEvent e) async {
print('Location $l Event: $e');
final SendPort send =
IsolateNameServer.lookupPortByName('geofencing_send_port');
send?.send(e.toString());
}
Future<void> initGeofence() async {
try {
bool isInitialized = await Geofence.initialize();
print("Geofence plugin initialzed : $isInitialized");
var region = GeofenceRegion(Location(18.4825, 73.7973), 3000.00);
bool geofenceAdded = await Geofence.registerGeofence(region, callback);
//await Geofence.unRegisterGeofence();
} catch (e) {
print(e);
}
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
platformVersion = await Geofence.platformVersion;
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: const Text('Plugin example app'),
),
body: new Center(
child: new Text('Running on: $_platformVersion\n'),
),
),
);
}
}
Use this package as a library
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies:
geofence: ^1.0.3
2. Install it
You can install packages from the command line:
with Flutter:
$ flutter pub get
Alternatively, your editor might support flutter pub get
.
Check the docs for your editor to learn more.
3. Import it
Now in your Dart code, you can use:
import 'package:geofence/geofence.dart';
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
75
|
Health:
Code health derived from static analysis.
[more]
|
100
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
98
|
Overall:
Weighted score of the above.
[more]
|
87
|
We analyzed this package on Dec 13, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
- Dart: 2.7.0
- pana: 0.13.1+4
- Flutter: 1.12.13+hotfix.4
Health suggestions
Format lib/geofence.dart
.
Run flutter format
to format lib/geofence.dart
.
Maintenance suggestions
Package is getting outdated. (-1.64 points)
The package was last published 53 weeks ago.
Dependencies
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.0.0-dev.68.0 <3.0.0 | ||
flutter | 0.0.0 | ||
Transitive dependencies | |||
collection | 1.14.11 | 1.14.12 | |
meta | 1.1.8 | ||
sky_engine | 0.0.99 | ||
typed_data | 1.1.6 | ||
vector_math | 2.0.8 |