background_locator
background_locator copied to clipboard
Null check operator used on a null value
Hi! I am just trying out this plugin but keep running into the null check issue, here is my code
void getLocationLiveUpdates() async {
await BackgroundLocator.initialize();
await BackgroundLocator.isServiceRunning();
BackgroundLocator.registerLocationUpdate((LocationDto data) {
BackgroundLocator.updateNotificationText(
title: "new location received",
msg: "${DateTime.now()}",
bigMsg: "${data.latitude}, ${data.longitude}");
});
}
The error log
[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Null check operator used on a null value
E/flutter (27770): #0 SettingsUtil._getCommonArgumentsMap
package:background_locator/utils/settings_util.dart:39
E/flutter (27770): #1 SettingsUtil.getArgumentsMap
package:background_locator/utils/settings_util.dart:17
E/flutter (27770): #2 BackgroundLocator.registerLocationUpdate
package:background_locator/background_locator.dart:37
I think you can't use lambda callback, use global or static callback instead
I think you can't use lambda callback, use global or static callback instead
Yes this is the, exact reason for getting this error
I think you can't use lambda callback, use global or static callback instead
Yes this is the, exact reason for getting this error
Hi habil! I am new to flutter and can't implement static or global call back can you please post your code snippet of this implementation?
Hi, you just need to declare a static function like below:
static void backgroundLocationCallBack(LocationDto location) {
// do smth with location data
}
Then pass it as an initial argument to the registerLocationUpdate
function like below:
BackgroundLocator.registerLocationUpdate(backgroundLocationCallBack,
autoStop: true,
disposeCallback: backgroundLocationDisposeCallBack,
iosSettings: iOS.IOSSettings(.......),
androidSettings: android.AndroidSettings(.......));
Hi, you just need to declare a static function like below:
static void backgroundLocationCallBack(LocationDto location) { // do smth with location data }
Then pass it as an initial argument to the
registerLocationUpdate
function like below:BackgroundLocator.registerLocationUpdate(backgroundLocationCallBack, autoStop: true, disposeCallback: backgroundLocationDisposeCallBack, iosSettings: iOS.IOSSettings(.......), androidSettings: android.AndroidSettings(.......));
Thank you sir! @Habil24 @janosroden