如何在颤动中使用回调作为后台位置

潘南

我正在关注这个插件(学习)背景定位器我以前使用过其他后台位置插件,但它们不再维护。

我正在按照插件描述中描述的教程进行操作,到目前为止这是我的代码。我不确定回调到底是什么以及如何使用它。

到目前为止,这是我的代码,但我没有得到任何结果。

static void backgroundLocationCallBack(LocationDto location) async {
    await BackgroundLocator.initialize();
    await BackgroundLocator.isServiceRunning();
  }

  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,
            )));
  }
阿斯温·戈皮纳坦

回调用于在某些事件期间执行某些操作。

在这里,callback属性backgroundLocationCallBack作为它的值,并且根据包代码,它用于在LocationDto可用时执行适当的操作。LocationDto对象将包含您要查找的位置信息,您可以根据自己的用例使用它。

同样,disposeCallback用于在BackgroundLocator对象上调用 dispose 时执行某些操作。您可以执行诸如关闭所有为获取位置而打开的端口之类的操作。

还有其他回调,例如initCallbackinitDataCallback用于设置回调以初始化位置服务的各种参数并分别为参数提供初始数据。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章