geofence 1.0.3 copy "geofence: ^1.0.3" to clipboard
geofence: ^1.0.3 copied to clipboard

Flutter Geofence Plugin Background Job Support For Register Geofence & If Mobile enters for exit geofence flutter code get triggered

example/lib/main.dart

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'),
        ),
      ),
    );
  }
}
11
likes
30
pub points
18%
popularity

Publisher

unverified uploader

Flutter Geofence Plugin Background Job Support For Register Geofence & If Mobile enters for exit geofence flutter code get triggered

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on geofence