HeadlessEvent class
Event object provided to BackgroundGeolocation.registerHeadlessTask
Example
__main.dart
void myHeadlessTask(HeadlessEvent headlessEvent) async {
print('[HeadlessTask]: ${headlessEvent}');
// Implement a `case` for only those events you're interested in.
switch(headlessEvent.name) {
case bg.Event.TERMINATE:
bg.State state = headlessEvent.event;
print('- State: ${state}');
break;
case bg.Event.HEARTBEAT:
bg.HeartbeatEvent event = headlessEvent.event;
print('- HeartbeatEvent: ${event}');
break;
case bg.Event.LOCATION:
bg.Location location = headlessEvent.event;
print('- Location: ${location}');
break;
case bg.Event.MOTIONCHANGE:
bg.Location location = headlessEvent.event;
print('- Location: ${location}');
break;
case bg.Event.GEOFENCE:
bg.GeofenceEvent geofenceEvent = headlessEvent.event;
print('- GeofenceEvent: ${geofenceEvent}');
break;
case bg.Event.GEOFENCESCHANGE:
bg.GeofencesChangeEvent event = headlessEvent.event;
print('- GeofencesChangeEvent: ${event}');
break;
case bg.Event.SCHEDULE:
bg.State state = headlessEvent.event;
print('- State: ${state}');
break;
case bg.Event.ACTIVITYCHANGE:
bg.ActivityChangeEvent event = headlessEvent.event;
print('ActivityChangeEvent: ${event}');
break;
case bg.Event.HTTP:
bg.HttpEvent response = headlessEvent.event;
print('HttpEvent: ${response}');
break;
case bg.Event.POWERSAVECHANGE:
bool enabled = headlessEvent.event;
print('ProviderChangeEvent: ${enabled}');
break;
case bg.Event.CONNECTIVITYCHANGE:
bg.ConnectivityChangeEvent event = headlessEvent.event;
print('ConnectivityChangeEvent: ${event}');
break;
case bg.Event.ENABLEDCHANGE:
bool enabled = headlessEvent.event;
print('EnabledChangeEvent: ${enabled}');
break;
case bg.Event.NOTIFICATIONACTION:
String buttonId = headlessEvent.event;
print('NotificationAction: ${buttonId}');
break;
}
}
void main() {
runApp(HelloWorld());
// Register your headlessTask:
BackgroundGeolocation.registerHeadlessTask(myHeadlessTask);
}
Constructors
- HeadlessEvent(String name, dynamic params)
Properties
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
String representation of
HeadlessEvent
forprint
to logs.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited