I have a boolean bool isDriverAvailable=false which will check if the user is online or not, if it is online then the GeoFire plugin will update its latitude and longitude to the database.
I am using a background location for this project which has a callback
static void backgroundLocationCallBack(LocationDto location) method where I plan to implement this check and update the location.
this is my code so far
class _HomeTabPageState extends State<HomeTabPage>
with AutomaticKeepAliveClientMixin, OSMMixinObserver {
bool isDriverAvailable = false;
//some code
static void backgroundLocationCallBack(LocationDto location) async {
print("from background location +${location.latitude}");
if (isDriverAvailable)
Geofire.setLocation(
currentFirebaseUser!.uid, location.latitude!, location.longitude!);
}
void getLocationLiveUpdates() async {
return await BackgroundLocator.registerLocationUpdate(
backgroundLocationCallBack,
autoStop: false,
// disposeCallback: backgroundLocationDisposeCallBack,
androidSettings: AndroidSettings(
accuracy: LocationAccuracy.NAVIGATION,
interval: 5,
distanceFilter: 0,
client: LocationClient.google,
androidNotificationSettings: AndroidNotificationSettings(
notificationChannelName: 'Location tracking',
notificationTitle: 'Start Location Tracking',
notificationMsg: 'Track location in background',
notificationBigMsg:
'Background location is on to keep the app up-tp-date with your location. This is required for main features to work properly when the app is not running.',
notificationIconColor: Colors.grey,
)));
}
I get an error on if (isDriverAvailable)
The error
Instance members can't be accessed from a static method.
Try removing the reference to the instance member, or removing the keyword 'static' from the method.
I can't remove the static keyboard on backgroundLocationCallBack(LocationDto location) as it is only meant to work with static method.
How else can I implement the bool check ?