void headlessTask(bg.HeadlessEvent headlessEvent) async {
print('[BackgroundGeolocation 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;
}
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
await Firebase.initializeApp();
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
runApp(_MainApp());
bg.BackgroundGeolocation.registerHeadlessTask(headlessTask);
}
## Expected Behavior
<!--- Tell us what should happen -->
## Actual Behavior
<!--- Tell us what happens instead -->
## Steps to Reproduce
<!--- reproduce this issue; include code to reproduce, if relevant -->
1.
2.
3.
4.
## Context
<!--- What were you trying to do? -->
## Debug logs
<!-- include iOS / Android logs
- ios XCode logs,
- use #getLog #emailLog methods (@see docs)
- Android: $ adb logcat -s TSLocationManager
-->
<details>
<summary>Logs</summary>
``` <!-- syntax-highligting: DO NOT REMOVE -->
Launching lib\main.dart on SM N985F in debug mode...
Running Gradle task 'assembleDebug'...
[flutter_background_geolocation] Purging debug resources in release build
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find any matches for com.transistorsoft:tsbackgroundfetch:+ as no versions of com.transistorsoft:tsbackgroundfetch are available.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/transistorsoft/tsbackgroundfetch/maven-metadata.xml
- https://repo.maven.apache.org/maven2/com/transistorsoft/tsbackgroundfetch/maven-metadata.xml
- https://storage.googleapis.com/download.flutter.io/com/transistorsoft/tsbackgroundfetch/maven-metadata.xml
- file:/E:/salesforce/android/app/libs/com/transistorsoft/tsbackgroundfetch/maven-metadata.xml
- https://jcenter.bintray.com/com/transistorsoft/tsbackgroundfetch/maven-metadata.xml
Required by:
project :app > project :background_fetch
> Could not find any matches for com.transistorsoft:tslocationmanager:+ as no versions of com.transistorsoft:tslocationmanager are available.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/transistorsoft/tslocationmanager/maven-metadata.xml
- https://repo.maven.apache.org/maven2/com/transistorsoft/tslocationmanager/maven-metadata.xml
- https://storage.googleapis.com/download.flutter.io/com/transistorsoft/tslocationmanager/maven-metadata.xml
- file:/E:/salesforce/android/app/libs/com/transistorsoft/tslocationmanager/maven-metadata.xml
- https://jcenter.bintray.com/com/transistorsoft/tslocationmanager/maven-metadata.xml
Required by:
project :app > project :flutter_background_geolocation
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 44s
Exception: Gradle task assembleDebug failed with exit code 1
Your Environment
flutter doctor
):Plugin config: