getGeofence static method

Future<Geofence?> getGeofence(
  1. String identifier
)

Retrieve all a single Geofence by identifier.

Example

Geofence geofence = await BackgroundGeolocation.getGeofence("HOME");
print('[getGeofence HOME: ${geofence}');

Implementation

static Future<Geofence?> getGeofence(String identifier) async {
  try {
    Map data =
        (await _methodChannel.invokeMapMethod('getGeofence', identifier))!;
    dynamic loiteringDelay = data['loiteringDelay'];
    List<List<double>> vertices = [];
    if (data['vertices'] != null) {
      List<Object?> tmp = data['vertices'];
      tmp.forEach((vertex) {
        List<double> v = List.from(vertex as List);
        vertices.add(v);
      });
    }
    return Geofence(
        identifier: data['identifier'],
        radius: data['radius'],
        latitude: data['latitude'],
        longitude: data['longitude'],
        notifyOnEntry: data['notifyOnEntry'],
        notifyOnExit: data['notifyOnExit'],
        notifyOnDwell: data['notifyOnDwell'],
        loiteringDelay: (loiteringDelay.runtimeType == double)
            ? loiteringDelay.round()
            : loiteringDelay,
        vertices: vertices,
        extras: (data['extras'] != null)
            ? data['extras'].cast<String, dynamic>()
            : {});
  } on PlatformException catch (e) {
    if (e.code == "404") {
      return null;
    } else {
      throw Error(e);
    }
  }
}