当应用在FLUTTER中被杀死时,如何将位置数据发送到Firestore数据库

编程入门 行业动态 更新时间:2024-10-24 04:49:38
本文介绍了当应用在FLUTTER中被杀死时,如何将位置数据发送到Firestore数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在努力创建一个应用程序,即使应用程序被杀死,该应用程序也会将用户的位置数据发送到Firestore数据库.

I have been trying to create an app in flutter which sends the location data of a user to the Firestore Database EVEN WHEN THE APP IS KILLED.

当该应用被终止时,此插件可以很好地获取位置数据: github/rekab-app/background_locator

This plugin works well to get the location data when the app is killed: github/rekab-app/background_locator

问题是我无法在此插件的回调"功能中更新Firestore数据库值

The problem is that I am unable to update the Firestore Database values in the 'callback' function of this plugin

这是我的代码:

static void callback(LocationDto locationDto) async { print('location in dart: ${locationDto.toString()}'); final SendPort send = IsolateNameServer.lookupPortByName(_isolateName); send?.send(locationDto); await DatabaseService(uid:UID).updateUserLocation( (locationDto.latitude).toString(), (locationDto.longitude).toString()); }

DatabaseService.updateUserLocation方法为:

The DatabaseService.updateUserLocation method is:

Future updateUserLocation(String latitude,String longitude) async { return await location_collection.document(uid).setData({ 'Longitude':longitude, 'Latitude':latitude }); }

错误在于将locationDto发送到FireStore数据库 确切的错误是:

The error is in sending the locationDto to the FireStore Database The exact error is:

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method DocumentReference#setData on channel plugins.flutter.io/cloud_firestore)

这与updateUserLocation方法中的setData()函数有关.

This relates to the setData() function in the updateUserLocation method.

即使应用程序被杀死,如何将用户的位置数据发送到我的Firestore数据库中?

How do I send the location data of the user to my Firestore Database EVEN WHEN THE APP IS KILLED?

如果有人可以帮助我,那就太好了!!

It would be great if someone could help me on this!!!

谢谢!

推荐答案

获取令牌时,我在shared_preferences中也遇到了同样的情况.因此,我认为在回调方法内创建一个新实例并起作用.我的意思是,尝试像新对象一样在回调方法中调用location_collection.

I had the same situation with shared_preferences, when get token. So, I think in create a new instance inside callback method, and works. I mean, try to call location_collection inside callback method like new object.

并将其添加到应用"应用中

And added this in Application app

override fun registerWith(registry: PluginRegistry?) { if (!registry!!.hasPlugin("io.flutter.plugins.sharedpreferences")) { SharedPreferencesPlugin.registerWith(registry!!.registrarFor("io.flutter.plugins.sharedpreferences")) } }

更多推荐

当应用在FLUTTER中被杀死时,如何将位置数据发送到Firestore数据库

本文发布于:2023-11-27 08:34:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637306.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送到   用在   被杀   如何将   死时

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!